淘先锋技术网

首页 1 2 3 4 5 6 7

// for stdandard type

#pragma pack(push,8)
#pragma warning(push,3)

#pragma push_macro("new")
#undef new

inline void* __cdecl operator new(size_t size)
{
     return malloc(size);
}
inline void* __cdecl operator new(size_t size,const char*file,const int line)
{
     return malloc(size);
}
inline void __cdecl operator delete(void*ptr)
{
     return free(ptr);
}

inline void* __cdecl operator new[](size_t size)
{
     return ::operator new(size);
}
inline void __cdecl operator delete[](void* p)
{
     ::operator delete(p);
}

inline void * __cdecl operator new( size_t size, void *p )

     return  realloc( p,size);
}
inline void * __cdecl operator new[]( size_t size, void *p )

     return  realloc( p,size);
}

#pragma pop_macro("new")

//for c++ class

class CWnd

{

     inline void* operator new(size_t size)
     {    
         return malloc(size);
     }
     inline void*operator new(size_t size,const char*file,const int line)
     {
         return malloc(size);
     }
     inline void operator delete(void*ptr)
     {
         return free(ptr);
     }     
     inline void* operator new[](size_t size)
     {
         void* p =  malloc(size);
         return p;
     }    
     inline void operator delete[](void* p)
     {
         operator delete(p);
     } 
     void *operator new( size_t size, void *p ) 
     { 
         return  realloc( p,size);
     }
     void *operator new[]( size_t size, void *p ) 
     { 
         unsigned int * p1 = (unsigned int*)((unsigned int) p - 4);
         CWnd* p2 = (CWnd*)p;
         for( int i = 0;i<size;i++)
              p2[i].~CWnd();
         return  realloc( p1,size);
     }

}

转载于:https://www.cnblogs.com/cgwolver/archive/2009/01/15/1376248.html