Crossware

Table of Contents        Previous topic       

C++ COMPILER LIBRARY FUNCTIONS->new and delete

#include <new>

void* operator new( unsigned int cb )

Allocates cb bytes of heap memory and calls the constructor of the object.

Returns a pointer to the object.

Note that it is not necessary to include the header <new> to use this operator.

Example:

string* pstr = new string;

void* operator new[]( unsigned int cb )

Allocates cb multiplied by the number of array elements bytes of heap memory and calls each constructor of the objects in the array in order starting with the first element.

Returns a pointer to the first object in the array.

Note that it is not necessary to include the header <new> to use this operator.

Example:

char* psz = new char[10];


void operator delete( void * p )

Calls the destructor of the object and deallocates the heap memory allocated by the new operator.

Note that it is not necessary to include the header <new> to use this operator.

Example:

delete pstr;

void operator delete[]( void * p )

Calls the destructors of the array of objects in reverse order to their construction and deallocates the heap memory allocated by the new operator.

Note that it is not necessary to include the header <new> to use this operator.

Example:

delete[] psz;

void* operator new( unsigned int cb, void* p )

(new-placement syntax)

Calls the constructor of the object using p as a pointer to the memory for the object.

Returns p.

Example:

string* pstr = new(p) string;

where p is a void pointer to some previously allocated memory.

void* operator new[]( unsigned int cb, void* p )

(new-placement syntax)

Calls the constructors of an array of objects in order starting with the first element using p as a pointer to the memory for the objects.

Returns p.

Example:

char* psz = new(p) char[10];

where p is a void pointer to some previously allocated memory.