_new_handler

From RAD Studio
Jump to: navigation, search

Go Up to new.h Index


Header File

new.h

Syntax

typedef void (*pvf)();

pvf _new_handler;

Description

_new_handler contains a pointer to a function that takes no arguments and returns void. If operator new() is unable to allocate the space required, it will call the function pointed to by _new_handler; if that function returns it will try the allocation again. By default, the function pointed to by _new_handler simply terminates the application. The application can replace this handler, however, with a function that can try to free up some space. This is done by assigning directly to _new_handler or by calling the function set_new_handler, which returns a pointer to the former handler.

As an alternative, you can set using the function set_new_handler, like this:

pvf set_new_handler(pvf p);

_new_handler is provided primarily for compatibility with C++ version 1.2. In most cases this functionality can be better provided by overloading operator new().

Example