|
Description |
Provides an error handler for mallocx() | ||
|
Syntax |
handler DP4D mallocx_handler; | ||
|
Parameters |
handler ANY DP4P (* handler)() | ||
|
Remarks |
If this variable is set to point to an error-handling function, it is called when mallocx() is about to return 0 as a result of heap exhaustion. For example, a simple but effective error handler is:
This avoids you having to check the return code of mallocx(). A more sophisticated version is as follows:
To prevent infinite recursion where mallocx() is called from the handler, set mallocx_handler to 0 temporarily before the handler function is called and restore it afterwards. If you set mallocx_handler again within the handler routine, it is your responsibility to control recursion. |