Detailed Description
Libcwd does a weak attempt to support debugging of memory leaks. I hope to greatly improve this in the future.It is possible to mark allocations that are done till that moment, and then later check for memory leaks by expecting no other memory allocations than those that already existed before the mark. This is done by creating a marker_ct object. The check for memory leaks is done when the marker is removed again. This can be done recursively.A
marker is created by passing it a description:
#if CWDEBUG_MARKER
#endif
A memory allocation marker.
Definition: class_marker.h:33
Any allocation done
after the creation of this marker will be reported as a
leak at the moment the
marker is deleted.Markers are clearly visible in the Allocated memory Overview. They are labeled MARKER (see also the
allocator type table). All memory that is allocated after a
marker, is displayed indented and below that marker in the Allocated memory Overview.Finally, it is possible to move specific memory blocks outside markers, so they will not cause a memory leak detection. This is done with the function
}
void move_outside(marker_ct *marker, void const *void_ptr)
Move memory allocation pointed to by ptr outside marker.
Definition: debugmalloc.cc:3487
namespace for libcwd.
Definition: debug.cc:87
which would move the memory allocation pointed to by
ptr outside the test region of
marker.A complete example program with output is given here:
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
class A {
int i;
int j;
char k;
};
int main(int argc, char* argv[])
{
A* a1 = new A;
AllocTag(a1, "First created");
#if CWDEBUG_MARKER
#endif
A* a2 = new A[10];
AllocTag(a2, "Created after the marker");
int* p = new int[30];
AllocTag(p, "Created after the marker");
#if CWDEBUG_MARKER
#endif
#if CWDEBUG_MARKER
delete marker;
#endif
#if CWDEBUG_ALLOC
#else
#endif
}
void on()
Cancel last call to off().
Definition: class_debug.inl:202
This is the main header file of libcwd.
#define Dout(cntrl, data)
Macro for writing debug output.
Definition: debug.h:154
#define Debug(STATEMENTS...)
Encapsulation macro for general debugging code.
Definition: debug.h:124
channel_ct malloc
Definition: debug.cc:474
fatal_channel_ct fatal
Definition: debug.cc:527
channel_ct notice
Definition: debug.cc:460
channel_ct warning
Definition: debug.cc:485
void set_ostream(std::ostream *os)
Set output device (single threaded applications).
Definition: debug.cc:2041
#define DoutFatal(cntrl, data)
Macro for writing fatal debug output to the default debug object libcw_do .
Definition: debug.h:164
void make_all_allocations_invisible_except(void const *ptr)
Make all current allocations invisible except the given pointer.
Definition: debugmalloc.cc:3219
unsigned long list_allocations_on(debug_ct &debug_object)
List all current allocations to a given debug object.
Definition: debugmalloc.cc:3020
#define ForAllDebugChannels(STATEMENT...)
Looping over all debug channels.
Definition: debug.h:190
debug_ct libcw_do
The default debug object.
Definition: debug.cc:429