debug_new.h File Reference

Back to the index.

Classes | Macros | Functions | Variables
debug_new.h File Reference
#include <new>
#include <stdio.h>

Go to the source code of this file.

Classes

class  __debug_new_counter
 Part of Wu Yongwei's new/delete debug memory leak detector. More...
 

Macros

#define HAS_PLACEMENT_DELETE   1
 
#define _DEBUG_NEW_REDEFINE_NEW   1
 
#define DEBUG_NEW   new(__FILE__, __LINE__)
 
#define new   DEBUG_NEW
 

Functions

int check_leaks ()
 
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
 
bool new_verbose_flag
 
FILE * new_output_fp
 
const char * new_progname
 

Detailed Description

Header file for checking leaks caused by unmatched new/delete.

Version
3.4, 2005/09/13
Author
Wu Yongwei

Definition in file debug_new.h.

Macro Definition Documentation

◆ _DEBUG_NEW_REDEFINE_NEW

#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

Definition at line 92 of file debug_new.h.

◆ DEBUG_NEW

#define DEBUG_NEW   new(__FILE__, __LINE__)

The macro to catch file/line information on allocation. If _DEBUG_NEW_REDEFINE_NEW is not defined, one can use this macro directly; otherwise new will be defined to it, and one must use new instead.

Definition at line 124 of file debug_new.h.

◆ HAS_PLACEMENT_DELETE

#define HAS_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.

Definition at line 64 of file debug_new.h.

◆ new

#define new   DEBUG_NEW

Definition at line 127 of file debug_new.h.

Function Documentation

◆ check_leaks()

int check_leaks ( )

Checks for memory leaks.

Returns
zero if no leakage is found; the number of leaks otherwise

Definition at line 497 of file debug_new.cc.

References _DEBUG_NEW_HASHTABLESIZE, aligned_list_item_size, new_ptr_list_t::line, and new_ptr_list_t::size.

Referenced by internal_w(), and __debug_new_counter::~__debug_new_counter().

◆ operator delete()

void operator delete ( void *  pointer,
const char *  file,
int  line 
)
throw (
)

◆ operator delete[]()

void operator delete[] ( void *  pointer,
const char *  file,
int  line 
)
throw (
)

◆ operator new()

void* operator new ( size_t  size,
const char *  file,
int  line 
)

◆ operator new[]()

void* operator new[] ( size_t  size,
const char *  file,
int  line 
)

Variable Documentation

◆ new_autocheck_flag

bool new_autocheck_flag

Flag to control whether check_leaks will be automatically called on program exit.

Definition at line 261 of file debug_new.cc.

◆ new_output_fp

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).

Definition at line 273 of file debug_new.cc.

◆ new_progname

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("_");'.

Definition at line 283 of file debug_new.cc.

◆ new_verbose_flag

bool new_verbose_flag

Flag to control whether verbose messages are output.

Definition at line 266 of file debug_new.cc.


Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13