new and delete
// Example 1
// Allocation
T* pv = (T*)malloc( sizeof(T) );
// Construction
::new( pv ) T( /*arg-list*/ );
...
// Destruction
pv->T::~T();
// Deallocation
free( pv );
// Example 2
class Blanks
{
public:
Blanks(){}
void* operator new( size_t stAllocateBlock, int chInit )
{
void* pvTemp = malloc( stAllocateBlock );
if( pvTemp != 0 )
{
memset( pvTemp, chInit, stAllocateBlock );
}
return pvTemp;
}
};
// For discrete objects of type Blanks, the global operator new function
// is hidden. Therefore, the following code allocates an object of type
// Blanks and initializes it to 0xa5
Blanks *a5 = new(0xa5) Blanks;
bool b = a5 != 0;