31 #ifndef ZenMemoryDebugH
32 #define ZenMemoryDebugH
36 #if defined(ZENLIB_DEBUG)
56 static MemoryDebug& Instance();
58 void* Allocate(std::size_t Size,
const char* File,
int Line,
bool Array);
59 void Free(
void* Ptr,
bool Array);
60 void NextDelete(
const char*,
int Line);
72 typedef std::map<void*, TBlock> TBlockMap;
75 std::stack<TBlock> m_DeleteStack;
84 inline void*
operator new(std::size_t Size,
const char* File,
int Line)
86 return ZenLib::MemoryDebug::Instance().Allocate(Size, File, Line,
false);
88 inline void*
operator new[](std::size_t Size,
const char* File,
int Line)
90 return ZenLib::MemoryDebug::Instance().Allocate(Size, File, Line,
true);
93 inline void operator delete(
void* Ptr)
95 ZenLib::MemoryDebug::Instance().Free(Ptr,
false);
98 inline void operator delete[](
void* Ptr)
100 ZenLib::MemoryDebug::Instance().Free(Ptr,
true);
103 #if !defined(__BORLANDC__) // Borland does not support overloaded delete
104 inline void operator delete(
void* Ptr,
const char* File,
int Line)
106 ZenLib::MemoryDebug::Instance().NextDelete(File, Line);
107 ZenLib::MemoryDebug::Instance().Free(Ptr,
false);
110 inline void operator delete[](
void* Ptr,
const char* File,
int Line)
112 ZenLib::MemoryDebug::Instance().NextDelete(File, Line);
113 ZenLib::MemoryDebug::Instance().Free(Ptr,
true);
117 #if !defined(__MINGW32__) //TODO: Does not work on MinGW, don't know why
119 #define new new(__FILE__, __LINE__)
122 #define delete ZenLib::MemoryDebug::Instance().NextDelete(__FILE__, __LINE__), delete
124 #endif // __MINGW32__
126 #endif // defined(ZENLIB_DEBUG)
128 #endif // ZenMemoryDebugH