debug_new.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00039 #ifndef _DEBUG_NEW_H
00040 #define _DEBUG_NEW_H
00041
00042 #include <new>
00043 #include <stdio.h>
00044
00056 #ifndef HAS_PLACEMENT_DELETE
00057 #define HAS_PLACEMENT_DELETE 1
00058 #endif
00059
00084 #ifndef _DEBUG_NEW_REDEFINE_NEW
00085 #define _DEBUG_NEW_REDEFINE_NEW 1
00086 #endif
00087
00088
00089 int check_leaks();
00090 void* operator new(size_t size, const char* file, int line);
00091 void* operator new[](size_t size, const char* file, int line);
00092 #if HAS_PLACEMENT_DELETE
00093 void operator delete(void* pointer, const char* file, int line) throw();
00094 void operator delete[](void* pointer, const char* file, int line) throw();
00095 #endif
00096 #if defined(_MSC_VER) && _MSC_VER < 1300
00097
00098
00099 void* operator new[](size_t) throw(std::bad_alloc);
00100 void operator delete[](void*) throw();
00101 #endif
00102
00103
00104 extern bool new_autocheck_flag;
00105 extern bool new_verbose_flag;
00106 extern FILE* new_output_fp;
00107 extern const char* new_progname;
00108
00117 #define DEBUG_NEW new(__FILE__, __LINE__)
00118
00119 # if _DEBUG_NEW_REDEFINE_NEW
00120 # define new DEBUG_NEW
00121 # endif
00122 # ifdef _DEBUG_NEW_EMULATE_MALLOC
00123 # include <stdlib.h>
00124 # ifdef new
00125 # define malloc(s) ((void*)(new char[s]))
00126 # else
00127 # define malloc(s) ((void*)(DEBUG_NEW char[s]))
00128 # endif
00129 # define free(p) delete[] (char*)(p)
00130 # endif
00131
00133 class __debug_new_counter
00134 {
00135 static int _count;
00136 public:
00137 __debug_new_counter();
00138 ~__debug_new_counter();
00139 };
00141 static __debug_new_counter __debug_new_count;
00142
00143 #endif // _DEBUG_NEW_H