Handling Insufficient Memory Conditions

Testing for failed memory allocation can be done with code such as the following:

int *pi = new int[BIG_NUMBER];

if( pi == 0 )
{
    cerr << "Insufficient memory" << endl;
    return -1;
}

There is an other ways to handle failed memory allocation requests: write a custom recovery routine to handle such a failure, then register your function by calling the _set_new_handler run-time function. This method is described in the following section.