29 #ifndef _MemoryTracker_H__
30 #define _MemoryTracker_H__
38 # pragma message "MemoryTracker included somewhere OgrePrerequisites.h wasn't!"
42 #if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 310 && !defined(STLPORT)
45 # if OGRE_COMP_VER >= 430
46 # include <tr1/unordered_map>
48 # include <ext/hash_map>
51 template <>
struct hash< void* >
53 size_t operator()(
void*
const & ptr )
const
63 #if OGRE_MEMORY_TRACKER
76 #if OGRE_MEMORY_TRACKER
97 Alloc() :bytes(0), line(0) {}
98 Alloc(
size_t sz,
unsigned int p,
const char* file,
size_t ln,
const char* func)
99 :bytes(sz), pool(p), line(ln)
108 std::string mLeakFileName;
110 typedef HashMap<void*, Alloc> AllocationMap;
111 AllocationMap mAllocations;
113 size_t mTotalAllocations;
114 typedef std::vector<size_t> AllocationsByPool;
115 AllocationsByPool mAllocationsByPool;
122 : mLeakFileName(
"OgreLeaks.log"), mDumpToStdOut(true),
123 mTotalAllocations(0), mRecordEnable(true)
129 void setReportFileName(
const std::string& name)
131 mLeakFileName = name;
134 const std::string& getReportFileName()
const
136 return mLeakFileName;
139 void setReportToStdOut(
bool rep)
144 bool getReportToStdOut()
const
146 return mDumpToStdOut;
152 size_t getTotalMemoryAllocated()
const;
154 size_t getMemoryAllocatedForPool(
unsigned int pool)
const;
166 void _recordAlloc(
void* ptr,
size_t sz,
unsigned int pool = 0,
167 const char* file = 0,
size_t ln = 0,
const char* func = 0);
169 void _recordDealloc(
void* ptr);
172 void setRecordEnable(
bool recordEnable)
174 mRecordEnable = recordEnable;
178 bool getRecordEnable()
const
180 return mRecordEnable;
188 mRecordEnable =
false;
192 static MemoryTracker&
get();