17 #ifndef ZenMemoryDebugH
18 #define ZenMemoryDebugH
22 #if defined(ZENLIB_DEBUG)
42 static MemoryDebug& Instance();
44 void* Allocate(std::size_t Size,
const char* File,
int Line,
bool Array);
45 void Free(
void* Ptr,
bool Array);
46 void NextDelete(
const char*,
int Line);
59 typedef std::map<void*, TBlock> TBlockMap;
62 std::stack<TBlock> m_DeleteStack;
71 inline void*
operator new(std::size_t Size,
const char* File,
int Line)
73 return ZenLib::MemoryDebug::Instance().Allocate(Size, File, Line,
false);
75 inline void*
operator new[](std::size_t Size,
const char* File,
int Line)
77 return ZenLib::MemoryDebug::Instance().Allocate(Size, File, Line,
true);
80 inline void operator delete(
void* Ptr)
82 ZenLib::MemoryDebug::Instance().Free(Ptr,
false);
85 inline void operator delete[](
void* Ptr)
87 ZenLib::MemoryDebug::Instance().Free(Ptr,
true);
90 #if !defined(__BORLANDC__) // Borland does not support overloaded delete
91 inline void operator delete(
void* Ptr,
const char* File,
int Line)
93 ZenLib::MemoryDebug::Instance().NextDelete(File, Line);
94 ZenLib::MemoryDebug::Instance().Free(Ptr,
false);
97 inline void operator delete[](
void* Ptr,
const char* File,
int Line)
99 ZenLib::MemoryDebug::Instance().NextDelete(File, Line);
100 ZenLib::MemoryDebug::Instance().Free(Ptr,
true);
104 #if !defined(__MINGW32__) //TODO: Does not work on MinGW, don't know why
106 #define new new(__FILE__, __LINE__)
109 #define delete ZenLib::MemoryDebug::Instance().NextDelete(__FILE__, __LINE__), delete
111 #endif // __MINGW32__
113 #endif // defined(ZENLIB_DEBUG)
115 #endif // ZenMemoryDebugH