MemoryLeakIndicator
Lade ...
Suche ...
Keine Treffer
MemoryLeakIndicator.h
gehe zur Dokumentation dieser Datei
1#ifndef INC_MEMORYLEAKINDICATOR_H
2#define INC_MEMORYLEAKINDICATOR_H
3//-----------------------------------------------------------------------------
32//-----------------------------------------------------------------------------
33#ifdef _MSC_VER
34 /* 'Bezeichner': Klasse 'Typ' benötigt eine DLL-Schnittstelle, die von... */
35 #pragma warning( disable : 4251 )
36#endif
37//-----------------------------------------------------------------------------
38#if __cplusplus >= 201103L
39 #include <mutex>
40#endif
41#include <unordered_map>
42
43#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
44 #include <basetsd.h>
45#elif defined(__GNUC__)
46 #define INT_PTR intptr_t
47#endif
48#include <stdarg.h>
49#include <windows.h>
50//-----------------------------------------------------------------------------
51// DLL Define __MEM_LEAK_INDICATOR_EXPORT_DLL
52#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
53 #ifdef __MEM_LEAK_INDICATOR_EXPORT_DLL
54 #define __mem_leak_indicator_export_dll __declspec(dllexport)
55 #if defined(_MSC_VER)
56 #pragma message ( "Benutze Export defines fuer __mem_leak_indicator_export_dll" )
57 #endif
58 #else
59 #define __mem_leak_indicator_export_dll //__declspec(dllimport)
60 #if defined(_MSC_VER)
61 #pragma message ( "Benutze Import defines fuer __mem_leak_indicator_export_dll" )
62 #endif
63 #endif
64#elif defined(__GNUC__)
65 #ifdef __MEM_LEAK_INDICATOR_EXPORT_DLL
66 #define __mem_leak_indicator_export_dll //__attribute__ ((visibility("default")))
67 #else
68 #define __mem_leak_indicator_export_dll //__attribute__ ((visibility ("hidden")))
69 #endif
70#endif
71//-----------------------------------------------------------------------------
83#ifndef nullptr
84 #if __cplusplus >= 201103L
85 #define nullptr nullptr
86 #else
87 #define nullptr NULL
88 #endif // __cplusplus >= 201103L
89#endif
90//-----------------------------------------------------------------------------
91namespace MemSpy
92{
93 //---------------------------------------------------------------------------
105 typedef bool TbExceptionMode;
106 //---------------------------------------------------------------------------
119 //---------------------------------------------------------------------------
129 const TbExceptionMode THROW = true;
130 //---------------------------------------------------------------------------
131
132 //---------------------------------------------------------------------------
144 typedef int TiOutput;
145 //---------------------------------------------------------------------------
158 //---------------------------------------------------------------------------
170 //---------------------------------------------------------------------------
183 //---------------------------------------------------------------------------
184
185 //---------------------------------------------------------------------------
228 //---------------------------------------------------------------------------
229
230 //---------------------------------------------------------------------------
248 {
249 public:
250 void operator()( PCSTR pszFormat, ... );
251 void operator()( PCWSTR pszFormat, ... );
252 };
253
254 //---------------------------------------------------------------------------
274 {
275 public:
276 //-----------------------------------------------------------------------
277 // >>>>>>>>>>>>>>>>>>>>>>>>> MemoryItem >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
278 //-----------------------------------------------------------------------
294 {
295 //============== Attribute
296 //---------------------------------------------------------------------
306 INT_PTR m_pItemPtr;
307 //---------------------------------------------------------------------
317 char const * m_FileName;
318 //---------------------------------------------------------------------
329 //---------------------------------------------------------------------
330 };
331 //-----------------------------------------------------------------------
332 // <<<<<<<<<<<<<<<<<<<<<<<<< MemoryItem <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
333 //-----------------------------------------------------------------------
334
335 private:
336 //============== Attribute
337 //-----------------------------------------------------------------------
349 #if __cplusplus >= 201103L
350 std::mutex m_LocalCriticalSection;
351 #else
352 CRITICAL_SECTION m_LocalCriticalSection;
353 #endif
354 //-----------------------------------------------------------------------
366 std::unordered_map< INT_PTR, MemoryItem * > m_ObjectList;
367 //-----------------------------------------------------------------------
377 std::unordered_map< INT_PTR, MemoryItem * >::iterator m_ObjectListIterator;
378 //-----------------------------------------------------------------------
388 unsigned long long m_ullInsertCounter;
389 //-----------------------------------------------------------------------
390
391 //========== static Attribute =========
392 //-----------------------------------------------------------------------
405 static bool ms_bUseLeakMap;
406 //-----------------------------------------------------------------------
417 //-----------------------------------------------------------------------
418
419 protected:
420 //============== Konstruktoren
421 //-----------------------------------------------------------------------
434 //-----------------------------------------------------------------------
446 virtual ~LeakMap();
447 //-----------------------------------------------------------------------
448
449 private:
450 //============== Konstruktoren
451 //-----------------------------------------------------------------------
461 LeakMap( const LeakMap & );
462 //-----------------------------------------------------------------------
463
464 public:
465 //========== static Methoden =========
466 //-----------------------------------------------------------------------
485 static LeakMap * create();
486 //-----------------------------------------------------------------------
500 static int destroy();
501 //-----------------------------------------------------------------------
515 static void destroyAbsolutely();
516 //-----------------------------------------------------------------------
527 //-----------------------------------------------------------------------
528
529 public:
530 //============== Methoden
531 //-----------------------------------------------------------------------
546 void setLeakMapUseAllowed( bool bAllowed = true );
547 //-----------------------------------------------------------------------
565 bool leakMapUseAllowed() const;
566 //-----------------------------------------------------------------------
578 unsigned long long numberOfProcessedObjects() const;
579 //-----------------------------------------------------------------------
591 std::size_t sizeOfObjectList() const;
592 //-----------------------------------------------------------------------
625 //-----------------------------------------------------------------------
646 MemoryItem * getSpyObject( INT_PTR ipAddress );
647 //-----------------------------------------------------------------------
665 void insertSpyObject( void * pNewObject, char const * chFileName, int iLine );
666 //-----------------------------------------------------------------------
678 void removeSpyObject( void * pObjectToDelete );
679 //-----------------------------------------------------------------------
680
681 private:
682 //============== Operatoren
683 //-----------------------------------------------------------------------
693 LeakMap & operator= ( const LeakMap & );
694 //-----------------------------------------------------------------------
695 };
696 //---------------------------------------------------------------------------
697
698 //---------------------------------------------------------------------------
733 //---------------------------------------------------------------------------
751 //---------------------------------------------------------------------------
752} // namespace MemSpy
753//-----------------------------------------------------------------------------
754#ifdef _MSC_VER
755 /* 'Bezeichner': Klasse 'Typ' benötigt eine DLL-Schnittstelle, die von... */
756 #pragma warning( default : 4251 )
757#endif
758//-----------------------------------------------------------------------------
759#endif
#define __mem_leak_indicator_export_dll
Definition MemoryLeakIndicator.h:59
Klasse um vergessene Objekte im Speicher im Zugriff zu haben. Inspiriert von Rainer Grimm und Mouaz...
Definition MemoryLeakIndicator.h:274
unsigned long long numberOfProcessedObjects() const
MemoryItem * getSpyObject(INT_PTR ipAddress)
LeakMap(const LeakMap &)
static void destroyAbsolutely()
CRITICAL_SECTION m_LocalCriticalSection
Definition MemoryLeakIndicator.h:352
static int ms_iReferenceCounter
Definition MemoryLeakIndicator.h:416
std::unordered_map< INT_PTR, MemoryItem * >::iterator m_ObjectListIterator
Definition MemoryLeakIndicator.h:377
bool leakMapUseAllowed() const
std::size_t sizeOfObjectList() const
void insertSpyObject(void *pNewObject, char const *chFileName, int iLine)
static bool ms_bUseLeakMap
Definition MemoryLeakIndicator.h:405
void removeSpyObject(void *pObjectToDelete)
std::unordered_map< INT_PTR, MemoryItem * > m_ObjectList
Definition MemoryLeakIndicator.h:366
virtual ~LeakMap()
static LeakMap * create()
static LeakMap * getGlobalLeakMapInstance()
MemoryItem * getSpyObject(SeekMode eMode)
unsigned long long m_ullInsertCounter
Definition MemoryLeakIndicator.h:388
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:248
void operator()(PCWSTR pszFormat,...)
void operator()(PCSTR pszFormat,...)
Definition MemoryLeakIndicator.h:92
bool TbExceptionMode
Definition MemoryLeakIndicator.h:105
const TiOutput OUTPUT_TRACE
Definition MemoryLeakIndicator.h:182
SeekMode
Definition MemoryLeakIndicator.h:196
@ CURRENT
Definition MemoryLeakIndicator.h:226
@ NEXT
Definition MemoryLeakIndicator.h:216
@ START
Definition MemoryLeakIndicator.h:206
const TbExceptionMode NOTHROW
Definition MemoryLeakIndicator.h:118
void __mem_leak_indicator_export_dll finishMemoryMonitoring(MemSpy::TiOutput iOutput=MemSpy::OUTPUT_CONSOLE)
const TiOutput OUTPUT_NON
Definition MemoryLeakIndicator.h:157
int TiOutput
Definition MemoryLeakIndicator.h:144
const TiOutput OUTPUT_CONSOLE
Definition MemoryLeakIndicator.h:169
const TbExceptionMode THROW
Definition MemoryLeakIndicator.h:129
__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:294
int m_iLineNumber
Definition MemoryLeakIndicator.h:328
INT_PTR m_pItemPtr
Definition MemoryLeakIndicator.h:306
char const * m_FileName
Definition MemoryLeakIndicator.h:317