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
00037 #ifndef NVWA_DEBUG_NEW_H
00038 #define NVWA_DEBUG_NEW_H
00039
00040 #include <new>
00041 #include <stdio.h>
00042 #include "_nvwa.h"
00043 #include "c++11.h"
00044
00045
00046 void* operator new(size_t size, const char* file, int line);
00047 void* operator new[](size_t size, const char* file, int line);
00048 void operator delete(void* ptr, const char* file, int line) _NOEXCEPT;
00049 void operator delete[](void* ptr, const char* file, int line) _NOEXCEPT;
00050
00051 NVWA_NAMESPACE_BEGIN
00052
00077 #ifndef _DEBUG_NEW_REDEFINE_NEW
00078 #define _DEBUG_NEW_REDEFINE_NEW 1
00079 #endif
00080
00092 #ifndef _DEBUG_NEW_TYPE
00093 #define _DEBUG_NEW_TYPE 1
00094 #endif
00095
00096
00097 int check_leaks();
00098 int check_mem_corruption();
00099
00100
00101 extern bool new_autocheck_flag;
00102 extern bool new_verbose_flag;
00103 extern FILE* new_output_fp;
00104 extern const char* new_progname;
00105
00114 # if _DEBUG_NEW_TYPE == 1
00115 # define DEBUG_NEW NVWA::debug_new_recorder(__FILE__, __LINE__) ->* new
00116 # else
00117 # define DEBUG_NEW new(__FILE__, __LINE__)
00118 # endif
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* ptr);
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* ptr)
00157 { _M_process(ptr); return ptr; }
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 NVWA_NAMESPACE_END
00180
00181 #endif // NVWA_DEBUG_NEW_H