Wednesday 25 July 2012

new Library

<new>

The default behavior of new is to throw an exception of type bad_alloc if out of memory. This can be changed by writing a function (taking no parameters and returning void) and passing it to set_new_handler().
void handler() {throw bad_alloc();} // The default
set_new_handler(handler);
new(nothrow) may be used in place of new. If out of memory, it returns 0 rather than throw bad_alloc. int* p = new(nothrow) int[1000000000]; // p may be 0

No comments:

Post a Comment