#include <new>
#include <stdio.h>
Include dependency graph for debug_new.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Classes | |
class | __debug_new_recorder |
Recorder class to remember the call context. More... | |
class | __debug_new_counter |
Counter class for on-exit leakage check. More... | |
Defines | |
#define | HAVE_PLACEMENT_DELETE 1 |
Macro to indicate whether placement delete operators are supported on a certain compiler. | |
#define | _DEBUG_NEW_REDEFINE_NEW 1 |
Macro to indicate whether redefinition of new is wanted. | |
#define | DEBUG_NEW __debug_new_recorder(__FILE__, __LINE__) ->* new |
Macro to catch file/line information on allocation. | |
#define | new DEBUG_NEW |
Functions | |
int | check_leaks () |
Checks for memory leaks. | |
int | check_mem_corruption () |
Checks for heap corruption. | |
void * | operator new (size_t size, const char *file, int line) |
void * | operator new[] (size_t size, const char *file, int line) |
void | operator delete (void *pointer, const char *file, int line) throw () |
void | operator delete[] (void *pointer, const char *file, int line) throw () |
Variables | |
bool | new_autocheck_flag |
Flag to control whether check_leaks will be automatically called on program exit. | |
bool | new_verbose_flag |
Flag to control whether verbose messages are output. | |
FILE * | new_output_fp |
Pointer to the output stream. | |
const char * | new_progname |
Pointer to the program name. | |
static __debug_new_counter | __debug_new_count |
Counting object for each file including debug_new.h. |
#define _DEBUG_NEW_REDEFINE_NEW 1 |
Macro to indicate whether redefinition of new
is wanted.
If one wants to define one's own operator new
, to call operator new
directly, or to call placement new
, it should be defined to 0
to alter the default behaviour. Unless, of course, one is willing to take the trouble to write something like:
# ifdef new # define _NEW_REDEFINED # undef new # endif // Code that uses new is here # ifdef _NEW_REDEFINED # ifdef DEBUG_NEW # define new DEBUG_NEW # endif # undef _NEW_REDEFINED # endif
#define DEBUG_NEW __debug_new_recorder(__FILE__, __LINE__) ->* new |
Macro to catch file/line information on allocation.
If _DEBUG_NEW_REDEFINE_NEW is 0
, one can use this macro directly; otherwise new
will be defined to it, and one must use new
instead.
#define HAVE_PLACEMENT_DELETE 1 |
Macro to indicate whether placement delete operators are supported on a certain compiler.
Some compilers, like Borland C++ Compiler 5.5.1 and Digital Mars Compiler 8.42, do not support them, and the user must define this macro to 0
to make the program compile. Also note that in that case memory leakage will occur if an exception is thrown in the initialization (constructor) of a dynamically created object.
#define new DEBUG_NEW |
int check_leaks | ( | ) |
Checks for memory leaks.
int check_mem_corruption | ( | ) |
Checks for heap corruption.
void operator delete | ( | void * | pointer, | |
const char * | file, | |||
int | line | |||
) | throw () |
void operator delete[] | ( | void * | pointer, | |
const char * | file, | |||
int | line | |||
) | throw () |
void* operator new | ( | size_t | size, | |
const char * | file, | |||
int | line | |||
) |
void* operator new[] | ( | size_t | size, | |
const char * | file, | |||
int | line | |||
) |
__debug_new_counter __debug_new_count [static] |
Counting object for each file including debug_new.h.
bool new_autocheck_flag |
Flag to control whether check_leaks will be automatically called on program exit.
FILE* new_output_fp |
Pointer to the output stream.
The default output is stderr, and one may change it to a user stream if needed (say, new_verbose_flag is true
and there are a lot of (de)allocations).
const char* new_progname |
Pointer to the program name.
Its initial value is the macro _DEBUG_NEW_PROGNAME. You should try to assign the program path to it early in your application. Assigning argv[0]
to it in main is one way. If you use bash or ksh (or similar), the following statement is probably what you want: `new_progname = getenv("_");
'.
bool new_verbose_flag |
Flag to control whether verbose messages are output.