Managing Memory with Multiple Heaps

IBM C and C++ Compilers lets you create and use your own pools of memory, called heaps. You can use your own heaps in place of or in addition to the default IBM C and C++ Compilers runtime heap to improve the performance of your program.

Note: Many readers will not be interested in creating their own heaps. Using your own heaps is entirely optional, and your applications will work perfectly well using the default memory management provided (and used by) the IBM C and C++ Compilers runtime library. If you want to improve the performance and memory management of your program, multiple heaps can help you. Otherwise, you can ignore this section and any heap-specific library functions.

 

Why Use Multiple Heaps?
Using a single runtime heap is fine for most programs. However, using multiple heaps can be more efficient and can help you improve your program's performance and reduce wasted memory for a number of reasons:

You can create heaps of regular memory or shared memory, and you can have any number of heaps of any type. See Types of Memory for more information about the different types of memory for heaps. The only limit is the space available on your operating system (your machine's memory and swapper size, minus the memory required by other running applications).

IBM C and C++ Compilers provides heap-specific versions of the memory management functions, for example, umalloc and so on. Debug versions of all memory management functions are provided, including the heap-specific ones. IBM C and C++ Compilers also provides additional functions that you can use to create and manage your own heaps of memory, such as udefault.



Memory Management Functions
Types of Memory
Debugging Memory Heaps


Creating and Using a Fixed Size Heap
Creating and Using an Expandable Heap
Debugging Problems with Heap Memory
Changing the Default Heap Used in a Program
Example of Creating and Using a User Heap
Example of Creating and Using a Shared-Memory User Heap