MemoryLeakIndicator
Lade ...
Suche ...
Keine Treffer
MemoryLeakIndicator.h
gehe zur Dokumentation dieser Datei
1#ifndef INC_MEMORYLEAKINDICATOR_H
2#define INC_MEMORYLEAKINDICATOR_H
3//-----------------------------------------------------------------------------
36//-----------------------------------------------------------------------------
37#ifdef _MSC_VER
38 /* 'Bezeichner': Klasse 'Typ' benötigt eine DLL-Schnittstelle, die von... */
39 #pragma warning( disable : 4251 )
40#endif
41//-----------------------------------------------------------------------------
42#if __cplusplus >= 201103L
43 #include <mutex>
44#endif
45#include <unordered_map>
46
47#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
48 #include <basetsd.h>
49#elif defined(__GNUC__)
50 #define INT_PTR intptr_t
51#endif
52#include <stdarg.h>
53#include <windows.h>
54//-----------------------------------------------------------------------------
55// DLL Define __MEM_LEAK_INDICATOR_EXPORT_DLL
56#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
57 #ifdef __MEM_LEAK_INDICATOR_EXPORT_DLL
58 #define __mem_leak_indicator_export_dll __declspec(dllexport)
59 #if defined(_MSC_VER)
60 #pragma message ( "Benutze Export defines fuer __mem_leak_indicator_export_dll" )
61 #endif
62 #else
63 #define __mem_leak_indicator_export_dll //__declspec(dllimport)
64 #if defined(_MSC_VER)
65 #pragma message ( "Benutze Import defines fuer __mem_leak_indicator_export_dll" )
66 #endif
67 #endif
68#elif defined(__GNUC__)
69 #ifdef __MEM_LEAK_INDICATOR_EXPORT_DLL
70 #define __mem_leak_indicator_export_dll //__attribute__ ((visibility("default")))
71 #else
72 #define __mem_leak_indicator_export_dll //__attribute__ ((visibility ("hidden")))
73 #endif
74#endif
75//-----------------------------------------------------------------------------
87#ifndef NULL_PTR
88 #if __cplusplus >= 201103L
89 #define NULL_PTR nullptr
90 #else
91 #define NULL_PTR NULL
92 #endif // __cplusplus >= 201103L
93#endif
94//-----------------------------------------------------------------------------
95namespace MemSpy
96{
97 //---------------------------------------------------------------------------
109 typedef bool TbExceptionMode;
110 //---------------------------------------------------------------------------
123 //---------------------------------------------------------------------------
133 const TbExceptionMode THROW = true;
134 //---------------------------------------------------------------------------
135
136 //---------------------------------------------------------------------------
148 typedef int TiOutput;
149 //---------------------------------------------------------------------------
162 //---------------------------------------------------------------------------
174 //---------------------------------------------------------------------------
187 //---------------------------------------------------------------------------
188
189 //---------------------------------------------------------------------------
232 //---------------------------------------------------------------------------
233
234 //---------------------------------------------------------------------------
252 {
253 public:
254 void operator()( PCSTR pszFormat, ... );
255 void operator()( PCWSTR pszFormat, ... );
256 };
257
258 //---------------------------------------------------------------------------
278 {
279 public:
280 //-----------------------------------------------------------------------
281 // >>>>>>>>>>>>>>>>>>>>>>>>> MemoryItem >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
282 //-----------------------------------------------------------------------
298 {
299 //============== Attribute
300 //---------------------------------------------------------------------
310 INT_PTR m_pItemPtr;
311 //---------------------------------------------------------------------
321 char const * m_FileName;
322 //---------------------------------------------------------------------
333 //---------------------------------------------------------------------
334 };
335 //-----------------------------------------------------------------------
336 // <<<<<<<<<<<<<<<<<<<<<<<<< MemoryItem <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
337 //-----------------------------------------------------------------------
338
339 private:
340 //============== Attribute
341 //-----------------------------------------------------------------------
353 #if __cplusplus >= 201103L
354 std::mutex m_LocalCriticalSection;
355 #else
356 CRITICAL_SECTION m_LocalCriticalSection;
357 #endif
358 //-----------------------------------------------------------------------
370 std::unordered_map< INT_PTR, MemoryItem * > m_ObjectList;
371 //-----------------------------------------------------------------------
381 std::unordered_map< INT_PTR, MemoryItem * >::iterator m_ObjectListIterator;
382 //-----------------------------------------------------------------------
392 unsigned long long m_ullInsertCounter;
393 //-----------------------------------------------------------------------
394
395 //========== static Attribute =========
396 //-----------------------------------------------------------------------
409 static bool ms_bUseLeakMap;
410 //-----------------------------------------------------------------------
421 //-----------------------------------------------------------------------
422
423 protected:
424 //============== Konstruktoren
425 //-----------------------------------------------------------------------
438 //-----------------------------------------------------------------------
450 virtual ~LeakMap();
451 //-----------------------------------------------------------------------
452
453 private:
454 //============== Konstruktoren
455 //-----------------------------------------------------------------------
465 LeakMap( const LeakMap & );
466 //-----------------------------------------------------------------------
467
468 public:
469 //========== static Methoden =========
470 //-----------------------------------------------------------------------
489 static LeakMap * create();
490 //-----------------------------------------------------------------------
504 static int destroy();
505 //-----------------------------------------------------------------------
519 static void destroyAbsolutely();
520 //-----------------------------------------------------------------------
531 //-----------------------------------------------------------------------
532
533 public:
534 //============== Methoden
535 //-----------------------------------------------------------------------
550 void setLeakMapUseAllowed( bool bAllowed = true );
551 //-----------------------------------------------------------------------
569 bool leakMapUseAllowed() const;
570 //-----------------------------------------------------------------------
582 unsigned long long numberOfProcessedObjects() const;
583 //-----------------------------------------------------------------------
595 std::size_t sizeOfObjectList() const;
596 //-----------------------------------------------------------------------
629 //-----------------------------------------------------------------------
650 MemoryItem * getSpyObject( INT_PTR ipAddress );
651 //-----------------------------------------------------------------------
669 void insertSpyObject( void * pNewObject, char const * chFileName, int iLine );
670 //-----------------------------------------------------------------------
682 void removeSpyObject( void * pObjectToDelete );
683 //-----------------------------------------------------------------------
684
685 private:
686 //============== Operatoren
687 //-----------------------------------------------------------------------
697 LeakMap & operator= ( const LeakMap & );
698 //-----------------------------------------------------------------------
699 };
700 //---------------------------------------------------------------------------
701
702 //---------------------------------------------------------------------------
737 //---------------------------------------------------------------------------
755 //---------------------------------------------------------------------------
756} // namespace MemSpy
757//-----------------------------------------------------------------------------
758#ifdef _MSC_VER
759 /* 'Bezeichner': Klasse 'Typ' benötigt eine DLL-Schnittstelle, die von... */
760 #pragma warning( default : 4251 )
761#endif
762//-----------------------------------------------------------------------------
763#endif
#define __mem_leak_indicator_export_dll
Definition MemoryLeakIndicator.h:63
Klasse um vergessene Objekte im Speicher im Zugriff zu haben. Inspiriert von Rainer Grimm und Mouaz...
Definition MemoryLeakIndicator.h:278
unsigned long long numberOfProcessedObjects() const
MemoryItem * getSpyObject(INT_PTR ipAddress)
LeakMap(const LeakMap &)
static void destroyAbsolutely()
CRITICAL_SECTION m_LocalCriticalSection
Definition MemoryLeakIndicator.h:356
static int ms_iReferenceCounter
Definition MemoryLeakIndicator.h:420
std::unordered_map< INT_PTR, MemoryItem * >::iterator m_ObjectListIterator
Definition MemoryLeakIndicator.h:381
bool leakMapUseAllowed() const
std::size_t sizeOfObjectList() const
void insertSpyObject(void *pNewObject, char const *chFileName, int iLine)
static bool ms_bUseLeakMap
Definition MemoryLeakIndicator.h:409
void removeSpyObject(void *pObjectToDelete)
std::unordered_map< INT_PTR, MemoryItem * > m_ObjectList
Definition MemoryLeakIndicator.h:370
virtual ~LeakMap()
static LeakMap * create()
static LeakMap * getGlobalLeakMapInstance()
MemoryItem * getSpyObject(SeekMode eMode)
unsigned long long m_ullInsertCounter
Definition MemoryLeakIndicator.h:392
void setLeakMapUseAllowed(bool bAllowed=true)
static int destroy()
Klasse, um eine TRACE-Ausgaben auch im Releas-Modus ins Ausgabefenster schreiben zu können....
Definition MemoryLeakIndicator.h:252
void operator()(PCWSTR pszFormat,...)
void operator()(PCSTR pszFormat,...)
Definition MemoryLeakIndicator.h:96
bool TbExceptionMode
Definition MemoryLeakIndicator.h:109
const TiOutput OUTPUT_TRACE
Definition MemoryLeakIndicator.h:186
SeekMode
Definition MemoryLeakIndicator.h:200
@ CURRENT
Definition MemoryLeakIndicator.h:230
@ NEXT
Definition MemoryLeakIndicator.h:220
@ START
Definition MemoryLeakIndicator.h:210
const TbExceptionMode NOTHROW
Definition MemoryLeakIndicator.h:122
void __mem_leak_indicator_export_dll finishMemoryMonitoring(MemSpy::TiOutput iOutput=MemSpy::OUTPUT_CONSOLE)
const TiOutput OUTPUT_NON
Definition MemoryLeakIndicator.h:161
int TiOutput
Definition MemoryLeakIndicator.h:148
const TiOutput OUTPUT_CONSOLE
Definition MemoryLeakIndicator.h:173
const TbExceptionMode THROW
Definition MemoryLeakIndicator.h:133
__mem_leak_indicator_export_dll MemSpy::LeakMap * activateMemoryMonitoring(MemSpy::TbExceptionMode bExceptionMode=MemSpy::THROW)
Referenz auf das instantiierte Objekt mit Dateinamen und Zeile, in der es instantiiert wurde.
Definition MemoryLeakIndicator.h:298
int m_iLineNumber
Definition MemoryLeakIndicator.h:332
INT_PTR m_pItemPtr
Definition MemoryLeakIndicator.h:310
char const * m_FileName
Definition MemoryLeakIndicator.h:321