IBM C and C++ Compilers provides debug versions of both general memory management functions and heap-specific memory management functions. To automatically call the debug versions of these functions, specify the -qheapdebug compiler option when compiling your program. Bear in mind that specifying this option can significantly increase the memory requirements and running time of your program.
Memory Allocation Fill Pattern
Some debug functions set all the memory they allocate to
a specified fill pattern. This lets you easily locate areas in
memory that your program uses.
The debug_malloc, debug_realloc, and debug_umalloc functions sets allocated memory to a default repeating 0xAA fill pattern. To enable this fill pattern, export the HD_FILL environment variable.
The debug_free function sets all free memory to a repeating 0xFB fill pattern.
Skipping Heap Checks
Each debug function calls _heap_check
(or _uheap_check) to check the heap.
Although this is useful, it can also increase your program's
memory requirements and decrease its execution speed.
To reduce the overhead of checking the heap on every debug memory management function, you can control how often the functions check the heap with the HD_SKIP environment variable. You will not need to do this for most of your applications unless the application is extremely memory intensive.
Set HD_SKIP like any other environment variable. The syntax for HD_SKIP is:
set HD_SKIP=increment,[start]
where:
increment | Specifies how often you want the debug functions to check the heap. |
start | Optional. Use this parameter to start skipping heap checks after start calls to debug functions. |
Note: The comma separating the parameters is optional. |
When you use the start parameter to start skipping heap checks, you are trading off heap checks that are done implicitly against program execution speed. You should therefore start with a small increment (like 5) and slowly increase until the application is usable.
For example, if you specify:
set HD_SKIP=10
then every tenth debug memory function call performs a heap check. If you specify:
set HD_SKIP=5,100
then after 100 debug memory function calls, only every fifth call performs a heap check. Other than the heap check, the debug functions behave exactly the same as usual.
Using Stack Traces
Stack contents are traced for each allocated memory
object. If the contents of an object's stack change, the traced
contents are dumped.
The trace size is controlled by the HD_STACK environment variable. If this variable is not set, the compiler assumes a stack size of 10. To disable stack tracing, set the HD_STACK environment variable to 0.
Memory Management Functions
Managing Memory with Multiple
Memory Heaps
Types of Memory
Debugging Memory Heaps
Creating and Using a Fixed Size Heap
Creating and Using an Expandable Heap
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
-qheapdebug Compiler
Option
_debug_calloc - Allocate and
Initialize Memory
_debug_free - Free Allocated Memory
_debug_heapmin - Free Unused Memory
in the Default Heap
_debug_malloc - Allocate Memory
_debug_memcpy - Copy Bytes
_debug_memmove - Copy Bytes
_debug_memset - Set Bytes to Value
_debug_realloc - Reallocate Memory
Block
_debug_strcat - Concatenate Strings
_debug_strcpy - Copy Strings
_debug_strncat - Concatenate
Strings
_debug_strncpy - Copy Strings
_debug_strnset - Set Characters in
String
_debug_strset - Set Characters in
String
_debug_ucalloc - Reserve and
Initialize Memory from User Heap
_debug_uheapmin - Free Unused
Memory in User Heap
_debug_umalloc - Reserve Memory
Block from User Heap