The memory management functions defined by ANSI are calloc, malloc, realloc, and free. These regular functions allocate and free memory from the default run-time heap. IBM C and C++ Compilers has added another function, _heapmin, to return unused memory to the system. IBM C and C++ Compilers also provides different versions of each of these functions as extensions to the ANSI definition.
Both versions actually work the same way; they differ only in which heap they allocate from, and in whether they save information to help you debug memory problems. The memory allocated by all of these functions is suitably aligned for storing any type of object.
The run-time automatically pools objects from 1 to 512 bytes in size for the default runtime heap (_RUNTIME_HEAP), and aligns them on 8-byte boundaries. With this pooling objects are allocated and freed very quickly, and overhead is reduced. Any heap you create using _ucreate will not have a default pool; you must explicitly call _upool().
The following table summarizes the different versions of memory management functions, using malloc as an example of how the names of the functions change for each version.
| Regular Version | Debug Version | |
|---|---|---|
| Default Heap | malloc | _debug_malloc |
| User Heap | _umalloc | _debug_umalloc |
| _tmalloc | _debug_tmalloc |
To use these extensions, you must set the
language level to extended, either with the /Se compiler
option or the #pragma
langlvl(extended) directive.
![]()
Heap Errors
Heap-Specific
Functions
Tiled Memory Management
Functions
Tiled
Debug Functions
![]()
Improve
Memory Management
Debug
Heap Use
![]()
Differentiating
Between Memory Management Functions