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 HAVE_PLACEMENT_DELETE
00057 #define HAVE_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 int check_mem_corruption();
00091 void* operator new(size_t size, const char* file, int line);
00092 void* operator new[](size_t size, const char* file, int line);
00093 #if HAVE_PLACEMENT_DELETE
00094 void operator delete(void* pointer, const char* file, int line) throw();
00095 void operator delete[](void* pointer, const char* file, int line) throw();
00096 #endif
00097 #if defined(_MSC_VER) && _MSC_VER < 1300
00098
00099
00100 void* operator new[](size_t) throw(std::bad_alloc);
00101 void operator delete[](void*) throw();
00102 #endif
00103
00104
00105 extern bool new_autocheck_flag;
00106 extern bool new_verbose_flag;
00107 extern FILE* new_output_fp;
00108 extern const char* new_progname;
00109
00118 #define DEBUG_NEW __debug_new_recorder(__FILE__, __LINE__) ->* new
00119
00120 # if _DEBUG_NEW_REDEFINE_NEW
00121 # define new DEBUG_NEW
00122 # endif
00123 # ifdef _DEBUG_NEW_EMULATE_MALLOC
00124 # include <stdlib.h>
00125 # ifdef new
00126 # define malloc(s) ((void*)(new char[s]))
00127 # else
00128 # define malloc(s) ((void*)(DEBUG_NEW char[s]))
00129 # endif
00130 # define free(p) delete[] (char*)(p)
00131 # endif
00132
00138 class __debug_new_recorder
00139 {
00140 const char* _M_file;
00141 const int _M_line;
00142 void _M_process(void* pointer);
00143 public:
00148 __debug_new_recorder(const char* file, int line)
00149 : _M_file(file), _M_line(line) {}
00156 template <class _Tp> _Tp* operator->*(_Tp* pointer)
00157 { _M_process(pointer); return pointer; }
00158 private:
00159 __debug_new_recorder(const __debug_new_recorder&);
00160 __debug_new_recorder& operator=(const __debug_new_recorder&);
00161 };
00162
00169 class __debug_new_counter
00170 {
00171 static int _S_count;
00172 public:
00173 __debug_new_counter();
00174 ~__debug_new_counter();
00175 };
00177 static __debug_new_counter __debug_new_count;
00178
00179 #endif // _DEBUG_NEW_H