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

Allocation Annotation
Collaboration diagram for Allocation Annotation:


#define AllocTag1(p)
 Annotate type of p.
#define AllocTag2(p, desc)
 Annotate type of p with string literal desc as description.
#define AllocTag(p, x)
 Annotate type of p with a static description.
#define AllocTag_dynamic_description(p, x)
 Annotate type of p with a dynamic description.
#define NEW(x)
 Like operator new, but automatically annotates the type of x.

Detailed Description

When memory is allocated, the resulting pointer should be passed to AllocTag(), passing information that needs to be included in the overview of allocated memory.


char* buf = (char*)malloc(BUFSIZE);
AllocTag(buf, "Temporary buffer");

would result, in the Allocated memory Overview, in a line like:

malloc    0x804ff38 char [512], (size = 512); Temporary buffer


MyClass* p = new MyClass;
AllocTag(p, "This is an example");

would result in a line like:

0x804f80c MyClass, (size = 30); This is an example


int* keys = new int [n];
AllocTag(keys, "Array with " << n << " keys of " << my_get_name());

would result in a line like:

new[]     0x804f6b8 int [5], (size = 20); Array with 5 keys of Mr.Frubal.

It is allowed to call AllocTag() more then once for the same pointer, in that case the last call will simply override the previous calls.  It is also allowed to call AllocTag() for a pointer that is not allocated at all, in which case it is ignored.  The main reason for this is to allow the use of AllocTag(this, "description") in the constructor of any object, even in relation with (multiple) inheritance.

It is also allowed to call AllocTag() with a pointer which points inside an allocated memory block, which has the same effect as using the pointer to the start of it.

Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.