libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

Main Page Reference Manual Namespace List Compound List Namespace Members Compound Members File Members

# Memory Allocation Debug Support: Introduction
[Memory Allocation Debug Support]

Collaboration diagram for Memory Allocation Debug Support: Introduction:

Unless --disable-alloc was specified during configuration then the following memory allocation and de-allocation debugging features are provided by libcwd:

1. Checking if a pointer that is passed to a memory de-allocation function is valid; and if this pointer was previously returned by a corresponding allocation function.
2. Finding the start, size, place of allocation in the source code and allocator type of an allocated memory block when given a pointer which points inside of it (see Finding (Information About) Memory Allocations).
3. Providing means to add type info and a description to the Allocated memory Overview (using `AllocTag()`).
4. Listing an overview of allocated memory to a Debug Object.
5. Boundary checks of allocated blocks, by means of magic numbers (see also --enable-magic (CWDEBUG_MAGIC)).

Unfortunately it is impossible to support feature 3. in C++ without putting hooks in your code:

- After every memory allocation, the returned pointer should be passed to `AllocTag()`, passing information that needs to be included in the Allocated memory Overview (this is not needed, though allowed, after a call to `realloc()`).

A missing `AllocTag()` will only have effect on the Allocated memory Overview, showing `<unknown type>` instead of the type and a description of the allocated object.