9 #include <tbb/atomic.h>
12 #include <boost/function.hpp>
14 #ifndef USE_VLD_MEMORY_TRACKING
15 #define DT_OBJECT_DEBUGGING_ENABLED
20 #ifdef DT_OBJECT_TRACKING_ENABLED
21 #include <tbb/spin_mutex.h>
27 template <
typename D,
bool Enable = false>
30 template <
typename D,
bool Enable = false>
34 #ifndef DT_OBJECT_DEBUGGING_ENABLED
35 #define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
36 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type)
37 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(type)
40 template <
typename D,
bool Enable>
49 class DtObjectContainer;
55 template <
typename D,
bool Enable>
66 static std::string Print(std::string regex =
"");
67 static std::string PrettyPrintSize(
size_t);
68 static std::string DetectLeaks();
75 const DtObjectContainer* container = 0);
82 const DtObjectContainer* container = 0);
94 size_t size()
const {
return mySize; }
97 size_t totalSize()
const {
return value() * size(); }
100 const DtObjectContainer*
objects()
const {
return myObjects; }
123 #ifdef DT_OBJECT_TRACKING_ENABLED
130 typedef tbb::spin_mutex Mutex;
131 typedef std::list<const DtObjectTracker*> TrackableList;
132 typedef TrackableList::iterator Handle;
134 typedef boost::function<void (const DtObjectTracker&)> IterateFunction;
137 void remove(Handle h);
139 void iterate(
const IterateFunction&)
const;
140 void print(std::ostream&,
unsigned width = 0)
const;
143 mutable Mutex myMutex;
144 TrackableList myTrackables;
150 virtual std::string debugText()
const;
160 template <
typename D,
bool Enable>
163 DtObjectContainer::Handle myHandle;
173 template <
typename D,
bool Enable>
192 #ifdef DT_OBJECT_TRACKING_ENABLED
205 #ifdef DT_OBJECT_TRACKING_ENABLED
216 #ifdef DT_OBJECT_TRACKING_ENABLED
230 #ifdef DT_OBJECT_TRACKING_ENABLED
231 static DtObjectContainer theObjectContainer;
232 return &theObjectContainer;
239 template <
typename D>
248 template <
typename D,
bool Enabled>
255 #define DT_NAME_OBJECT_DEBUGGER(type, name) \
257 struct DtObjectDebuggerLabel< type > \
259 static inline std::string value() \
265 #define DT_DEFINE_OBJECT_DEBUGGER_NAME(type) \
267 struct DtObjectDebuggerLabel< type > \
269 static inline std::string value() \
275 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type) \
276 template <typename T> \
277 struct DtObjectDebuggerLabel< type <T> > \
279 static inline std::string value() \
281 std::string name( #type "<" ); \
282 name += DtObjectDebuggerLabel<T>::value(); \
288 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(type) \
289 template <typename T1, typename T2> \
290 struct DtObjectDebuggerLabel< type <T1,T2> > \
292 static inline std::string value() \
294 std::string name( #type "<" ); \
295 name += DtObjectDebuggerLabel<T1>::value(); \
297 name += DtObjectDebuggerLabel<T2>::value(); \