如何动态创建大量的小对象,同时又避免内存碎片呢?这里先把MSDN的一个例子贴出来,有时间再过来和大家解释,最近很忙,谅解,谅解:

  1. // new_op_new.cpp  
  2. // compile with: /EHsc  
  3. #include<new>  
  4. #include<iostream>  
  5.  
  6. using namespace std;  
  7.  
  8. class MyClass   
  9. {  
  10. public:   
  11.    MyClass( )  
  12.    {  
  13.       cout << "Construction MyClass." << this << endl;  
  14.    };  
  15.  
  16.    ~MyClass( )  
  17.    {  
  18.       imember = 0; cout << "Destructing MyClass." << this << endl;  
  19.    };  
  20.    int imember;  
  21. };  
  22.  
  23. int main( )   
  24. {  
  25.    // The first form of new delete  
  26.    MyClass* fPtr = new MyClass;  
  27.    delete fPtr;  
  28.  
  29.    // The second form of new delete  
  30.    MyClass* fPtr2 = newnothrow ) MyClass;  
  31.    delete fPtr2;  
  32.  
  33.    // The third form of new delete  
  34.    char x[sizeof( MyClass )];  
  35.    MyClass* fPtr3 = new( &x[0] ) MyClass;  
  36.    fPtr3 -> ~MyClass();  
  37.    cout << "The address of x[0] is : " << ( void* )&x[0] << endl;