Change the Default Heap

The regular memory management functions always use whatever heap is currently the default for that thread. The initial default heap is the run-time heap provided by IBM C and C++ Compilers. 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 run-time 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 IBM C and C++ Compilers run-time heap, but you cannot alter the source code to use heap-specific calls. For example, if you set the default heap to a shared heap 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.

To change the default back to the IBM C and C++ Compilers run-time heap, call _udefault and specify _RUNTIME_HEAP (defined in <malloc.h>). You can also use this macro with any of the heap-specific functions to explicitly allocate from the run-time heap.



Manage Memory with Multiple Heaps


Heap-Specific Functions