Changing the default heap used in a program

The regular memory management functions (malloc and so on) always use the current default heap for that thread. The initial default heap for all XL C/C++ applications is the runtime heap provided by XL C/C++. However, you can make your own heap the default by calling _udefault. Then all calls to the regular memory management functions allocate memory from your heap instead of the default runtime heap.

The default heap changes only for the thread where you call _udefault. You can use a different default heap for each thread of your program if you choose. This is useful when you want a component (such as a vendor library) to use a heap other than the XL C/C++ default heap, but you cannot actually alter the source code to use heap-specific calls. For example, if you set the default heap to a shared heap and then call a library function that calls malloc, the library allocates storage in shared memory

Because _udefault returns the current default heap, you can save the return value and later use it to restore the default heap you replaced. You can also change the default back to the XL C/C++ default runtime heap by calling _udefault and specifying the _RUNTIME_HEAP macro (defined in umalloc.h). You can also use this macro with any of the heap-specific functions to explicitly allocate from the default runtime heap.