Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015
00019 #if defined (WIN32) && defined(_DEBUG) && defined(KNET_MEMORY_LEAK_CHECK)
00020
00021 #include <new>
00022 #include <crtdbg.h>
00023
00024 #ifndef _CRTDBG_MAP_ALLOC
00025 #define _CRTDBG_MAP_ALLOC
00026 #endif
00027
00028 __forceinline static void *operator new(size_t size, const char *file, int line)
00029 {
00030 return _malloc_dbg(size, _NORMAL_BLOCK, file, line);
00031 }
00032
00033 __forceinline static void *operator new[](size_t size, const char *file, int line)
00034 {
00035 return _malloc_dbg(size, _NORMAL_BLOCK, file, line);
00036 }
00037
00038 __forceinline static void operator delete(void *ptr, const char *, int)
00039 {
00040 _free_dbg(ptr, _NORMAL_BLOCK);
00041 }
00042
00043 __forceinline static void operator delete[](void *ptr, const char *, int)
00044 {
00045 _free_dbg(ptr, _NORMAL_BLOCK);
00046 }
00047
00048 __forceinline static void *operator new(size_t size)
00049 {
00050 #ifdef DEBUG_CPP_NAME
00051 return _malloc_dbg(size, _NORMAL_BLOCK, DEBUG_CPP_NAME, 1);
00052 #else
00053 return _malloc_dbg(size, _NORMAL_BLOCK, "(No CPP Name)", 1);
00054 #endif
00055 }
00056
00057 __forceinline static void *operator new[](size_t size)
00058 {
00059 #ifdef DEBUG_CPP_NAME
00060 return _malloc_dbg(size, _NORMAL_BLOCK, DEBUG_CPP_NAME " new[]", 1);
00061 #else
00062 return _malloc_dbg(size, _NORMAL_BLOCK, "(No CPP Name new[])", 1);
00063 #endif
00064 }
00065
00066 __forceinline static void operator delete(void *ptr)
00067 {
00068 _free_dbg(ptr, _NORMAL_BLOCK);
00069 }
00070
00071 __forceinline static void operator delete[](void *ptr)
00072 {
00073 _free_dbg(ptr, _NORMAL_BLOCK);
00074 }
00075
00076 #define new new (__FILE__, __LINE__)
00077
00078 #endif
00079