17 #ifndef ZenMemoryDebugH
18 #define ZenMemoryDebugH
22 #if defined(ZENLIB_DEBUG)
44 static MemoryDebug& Instance();
45 static bool g_IsShutdown;
46 void* Allocate(std::size_t Size,
const char* File,
int Line,
bool Array);
47 void Free(
void* Ptr,
bool Array);
48 void NextDelete(
const char*,
int Line);
61 typedef std::map<void*, TBlock> TBlockMap;
64 std::stack<TBlock> m_DeleteStack;
73 inline void*
operator new(std::size_t Size,
const char* File,
int Line)
75 return ZenLib::MemoryDebug::Instance().Allocate(Size, File, Line,
false);
77 inline void*
operator new[](std::size_t Size,
const char* File,
int Line)
79 return ZenLib::MemoryDebug::Instance().Allocate(Size, File, Line,
true);
82 inline void operator delete(
void* Ptr)
84 if (ZenLib::MemoryDebug::g_IsShutdown)
87 ZenLib::MemoryDebug::Instance().Free(Ptr,
false);
90 inline void operator delete[](
void* Ptr)
92 if (ZenLib::MemoryDebug::g_IsShutdown)
95 ZenLib::MemoryDebug::Instance().Free(Ptr,
true);
98 #if !defined(__BORLANDC__) // Borland does not support overloaded delete
99 inline void operator delete(
void* Ptr,
const char* File,
int Line)
101 ZenLib::MemoryDebug::Instance().NextDelete(File, Line);
102 ZenLib::MemoryDebug::Instance().Free(Ptr,
false);
105 inline void operator delete[](
void* Ptr,
const char* File,
int Line)
107 ZenLib::MemoryDebug::Instance().NextDelete(File, Line);
108 ZenLib::MemoryDebug::Instance().Free(Ptr,
true);
112 #if !defined(__MINGW32__) //TODO: Does not work on MinGW, don't know why
114 #define new new(__FILE__, __LINE__)
117 #define delete ZenLib::MemoryDebug::Instance().NextDelete(__FILE__, __LINE__), delete
119 #endif // __MINGW32__
121 #endif // defined(ZENLIB_DEBUG)
123 #endif // ZenMemoryDebugH