随笔分类 - C++
摘要:windows:Calculates the wall-clock time used by the calling process. return:The elapsed wall-clock time since the start of the processLinux:The clock() function returns an approximation of processor time used by the program Windows: 1 #include 2 #include 3 #include 4 5 int main() 6 { 7 printf...
阅读全文
摘要:简单例子如下:#include "Ice/Ice.h"#include "IceUtil/IceUtil.h"#include "Printer.h"using namespace std;using namespace Hello;class MyClass;typedef IceUtil::Handle MyClassPtr;class MyClass : public IceUtil::Shared{public: MyClass( int i) : _i(i){ { ...
阅读全文
摘要:delete void pointer是否会有内存泄漏?看下面一个简单例子class Test{public: Test(){ printf ("constructor\n"); } ~Test(){ printf("destructor"); }};int main(int argc, char *argv[]){ Test *p = new Test(); void *p1 = p; delete p1; printf("the end\n"); getchar(); return 0;} 结果输出:从输出可以看出来,没有调用类的
阅读全文
摘要:普通计时可以clock()精确计时:windows:QueryPerformanceCounter() linux:clock_gettime()用法:google参考:http://blog.csdn.net/pirate_code/article/details/5670055http://blog.chinaunix.net/uid-25909722-id-2827364.html
阅读全文
摘要:调试程序发现起了一个子线程后,主线程上的sleep不生效了,看到这才明白...— Function: unsigned intsleep(unsigned int seconds)Thesleepfunction waits forsecondsor until a signal is delivered, whichever happens first.Ifsleepfunction returns because the requested interval is over, it returns a value of zero. If it returns because of deli
阅读全文
摘要:/ *ObjectPool.h */#include <iostream>#include <queue>#include <vector>template <typename T>class ObjectPool{public: ObjectPool(size_t chunk_size = kdefault_size); ~ObjectPool(); T& acquire_object(); void release_object(T& obj);protected: void allocate_chunk(); static
阅读全文
摘要:dll 源文件 add.cppView Code 1 typedef int (*pfunc)(int, int); 2 pfunc myadd; 3 4 void __stdcall add(pfunc add) 5 { 6 myadd = add; 7 } 8 9 int __stdcall true_add(int x, int y)10 {11 return myadd(x, y);12 }def文件 add.defView Code 1 EXPORTS2 3 add @14 true_add @2 生成库ad...
阅读全文
摘要:字符串转换为数字函数:atoi(str):str最大为:2^31 - 1 //返回值为int类型atol(str):str最大为:2^63 - 1 //返回值为long long类型atof(str):str最大为:1.79769e+308 //返回值为double类型对于上面几个函数,str过大都会返回其最大值,如atoi会返回2^31 - 1double能表示的最大值:1.79769e+308测试方法最大值方法:#include <stdio.h>std::cout << DBL_MAX << std::endl;#include <limits&
阅读全文
摘要:什么是lib文件,lib和dll的关系如何(1)lib是编译时需要的,dll是运行时需要的。如果要完成源代码的编译,有lib就够了。如果也使动态连接的程序运行起来,有dll就够了。在开发和调试阶段,当然最好都有。(2)一般的动态库程序有lib文件和dll文件。lib文件是必须在编译期就连接到应用程序中的,而dll文件是运行期才会被调用的。如果有dll文件,那么对应的lib文件一般是一些索引信息,具体的实现在dll文件中。如果只有lib文件,那么这个lib文件是静态编译出来的,索引和实现都在其中。静态编译的lib文件有好处:给用户安装时就不需要再挂动态库了。但也有缺点,就是导致应用程序比较大,而
阅读全文
摘要:负载均衡策略:1.轮循均衡(Round Robin):每一次来自网络的请求轮流分配给内部中的服务器,从1至N然后重新开始。此种均衡算法适合于服务器组中的所有服务器都有相同的软硬件配置并且平均服务请求相对均衡的情况。2.权重轮循均衡(Weighted Round Robin):根据服务器的不同处理能力,给每个服务器分配不同的权值,使其能够接受相应权值数的服务请求。例如:服务器A的权值被设计成1,B的权值是3,C的权值是6,则服务器A、B、C将分别接受到10%、30%、60%的服务请求。此种均衡算法能确保高性能的服务器得到更多的使用率,避免低性能的服务器负载过重。3.随机均衡(Random):把来
阅读全文
摘要:原子操作、关中断、锁内存总线的机制
阅读全文
摘要:File:singleton.hpp 1 #ifndef __SINGLETON_HPP_ 2 #define __SINGLETON_HPP_ 3 4 template <class T> 5 class Singleton 6 { 7 public: 8 static T* Instance() { 9 if(!m_pInstance) m_pInstance = new T;10 assert(m_pInstance !=NULL);11 return m_pInstance;12 }13 protected:14 Singleton()...
阅读全文
摘要:1、 C++扩充很简单2、 Vs 的release版本不对内存做任何操作--à对数组做初始化。3、 new调用构造函数,delete调用析构函数。new分配的空间是连续的。4、 cin.get()、cin.getline()获取一行、cin.put()5、 输出:dec、setw() .etc。6、 This指针指向类的非static成员7、 Static 成员不是类对象的组成部分,其独立于任何对象存在。8、 浅拷贝、深拷贝。9、 EA工具。UML建模。10、 多用组合has-a,少用继承is-a。11、 基类的虚构函数一定要是虚函数,否则在用基类指针指向派生类对象只执行基类的析构函
阅读全文
摘要:说起const、static、以及#define大家都知道,我一直以为我也是知道的,昨天一同学说他面试时被问到#define定义一个常量和const定义一个常量有什么不同,我整理了下思路,发现当想向他说清楚这个问题时,我发现自己对const和#define中有些问题还是很模糊,我想这可能就是某位高手说的:“当你可以向别人清楚的解释某个问题时,你才算真正懂了这个问题”。于是乎,赶紧学习了下,理理思路,记下。1、c语言中:1 const int i=10;2 int array[i] ; 这个i不能说是常量而是一个不可改变的变量,它的不可改变是由编译器确定的,因此将 i 作为数组的长度;会出错,.
阅读全文
摘要:1、1 CString m_time;2 CTime theCurrentTime = CTime::GetCurrentTime();3 m_time = theCurrentTime.Format("%Y-%m-%d");2、1 struct tm *t;2 time_t tt;3 time(&tt);4 t=localtime(&tt);5 printf("%d-%d-%d\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday);author:good90参考:http://blog.
阅读全文
摘要:先上图经过这个礼拜的折腾,先是安装Mysql,学习下Mysql基本语句操作,学习下MFC操作,通过ODBC连接Mysql,参考各种网上的实例程序,加上自己的不断调试,修改,终于将这一可对数据库进行基本操作的程序写完(由于还是新手,,其中肯定有很多不完善的地方,希望各位高手帮忙指出。)下面记录下程序:安装建立mysql,连接ODBC以及通过MFC拖控件这些过程网上很多,就不写了,说一下我的mysql中有database mytest 内有表格mytable,如下:1、先通过vs2005建立一个MFC工程,vs自动生成文件如图:2、打开stdafx.h头文件,添加如下语句#include <
阅读全文
摘要:静态绑定:编译时绑定,通过对象调用动态绑定:运行时绑定,根据地址确定如下:C++类成员函数调用和绑定方式 图片来自于:http://wenku.baidu.com/view/4f97390016fc700abb68fcb5.html还有虚析构函数和虚函数表及其指针,由于时间和天气问题,明日继续。2012-02-2600:53:08前面说了动态绑定是根据地址来调用相应的函数,在C++中每个有虚函数的类中都有一个虚函数表,保存着该类中虚函数的地址,而根据地址调用相应函数,正是通过将指向该虚函数表的指针赋值给了基类的指针,想了解更多关于虚函数表的只是,看以看看这位大神写的,很详细:http://..
阅读全文
摘要:从一个程序入手,我们来看看虚函数: 1 #include <iostream> 2 using namespace std; 3 4 class A 5 { 6 public: 7 int ii; 8 /* void set_value(int val){i = val;}; 9 int get_value(){return i;}; */10 int a(){cout << "A::a" <<endl;11 return 0;}12 virtual void b(){cout << "A::b" <
阅读全文
浙公网安备 33010602011771号