Guiliani  Version 2.6 revision 7293 (documentation build 12)
GUIMemLeakDetection.h
1/*
2* Copyright (C) TES Electronic Solutions GmbH,
3* All Rights Reserved.
4* Contact: info@guiliani.de
5*
6* This file is part of the Guiliani HMI framework
7* for the development of graphical user interfaces on embedded systems.
8*/
9
12#ifndef GUIMEMLEAKDETECTION__H_
13#define GUIMEMLEAKDETECTION__H_
14
15#include "eC_Types.h"
16#include "eC_File.h"
17
18#define LEAK_DETECTION CGUIMemLeakDetection::GetInstance()
19
21
34
63{
64public:
65 /* The memory allocation functions need to access the private memory management methods
66 in this class, thus they are friend to this class.
67 */
68
69 friend void* Guiliani_malloc(size_t uiSize, const char* pFile, int iLine, const char* pFunction);
70 friend void Guiliani_free(void* pMemory, const char* pFile, int iLine, const char* pFunction);
71 friend void* Guiliani_realloc(void* pMemory, size_t uiSize, const char* pFile, int iLine, const char* pFunction);
72 friend void* Guiliani_new(size_t uiSize, const char* pFile, int iLine, const char* pFunction);
73 friend void* Guiliani_newArray(size_t uiSize, const char* pFile, int iLine, const char* pFunction);
74 friend void Guiliani_delete(void* pMemory, const char* pFile, int iLine, const char* pFunction);
75 friend void Guiliani_deleteArray(void* pMemory, const char* pFile, int iLine, const char* pFunction);
76
84 friend void* operator new(size_t uiSize, const char* pcFile, int iLine, const char* pcFunction);
85
93 friend void* operator new[](size_t uiSize, const char* pcFile, int iLine, const char* pcFunction);
94
98 friend void operator delete(void* Memory) throw();
99
103 friend void operator delete[](void* Memory) throw();
104
109 void WriteResultsToFile(const eC_Char* sFilename = "MemoryAnalysisResults.log", const eC_Bool& bAsTable = true);
110
113
117 const eC_UInt GetUsedMemory() const;
118
122 const eC_UInt GetMaxObject() const;
123
127 const eC_UInt GetLargestObject() const;
128
132 const eC_UInt GetCurrentlyLargestObject() const;
133
137 void SetActive(const eC_Bool& bActive);
138
139public:
144 {
145#ifdef GUILIANI_MEMORY_ALLOCATION_LOGGING
146 static CGUIMemLeakDetection s_MemLeakDetection(true);
147#else
148 static CGUIMemLeakDetection s_MemLeakDetection(false);
149#endif
150 return s_MemLeakDetection;
151 }
152
153private:
158 struct BlockHead_t
159 {
163 eC_UInt m_uiMagicNumber;
164
167 size_t m_uiObjectSize;
168 };
169
177 struct BlockInfo_t
178 {
180 BlockInfo_t()
181 {
182 m_pcFilename = NULL;
183 m_uiLine = 0;
184 m_pcFunction = NULL;
185 m_pMemoryAddress = NULL;
186 m_uiObjectSize = 0;
187 m_bIsArrayAlloc = false;
188 }
189
193 bool operator==(const BlockInfo_t& kValue) const
194 {
195 return m_pMemoryAddress == kValue.m_pMemoryAddress;
196 }
197
199 const eC_Char* m_pcFilename;
200
202 eC_UInt m_uiLine;
203
205 const eC_Char* m_pcFunction;
206
208 void* m_pMemoryAddress;
209
211 size_t m_uiObjectSize;
212
214 eC_Bool m_bIsArrayAlloc;
215 };
216
217private:
219 static const eC_UInt ms_cuiMagicNr = 395743214;
220
221private:
223 void* MemAlloc(
224 size_t Size,
225 const eC_Char* pFile,
226 eC_Int iLine,
227 const eC_Char* pFunction,
228 const eC_Char* pNewTypeName,
229 eC_Bool bIsArray);
230
232 void FreeMem(
233 void* pMemory,
234 const eC_Char* pFile,
235 eC_Int iLine,
236 const eC_Char* pFunction,
237 const eC_Char* pDeleteTypeName,
238 eC_Bool bIsArray);
239
241 void* MemRealloc(
242 void* pMemory,
243 size_t uiSize,
244 const eC_Char* pFile,
245 eC_Int iLine,
246 const eC_Char* pFunction);
247
249 CGUIMemLeakDetection(const eC_Bool& rkLogging);
250
255
259 CGUIMemLeakDetection& operator=(const CGUIMemLeakDetection& kSource);
260
263
264private:
266 eC_File* m_pkOutputFile;
267
269 const eC_Bool m_bLogState;
270
273 eC_UInt m_uiMemoryAllocSteps;
274
276 eC_UInt m_uiMemoryAllocStepsCounterDelete;
277
279 eC_UInt m_uiMemoryAllocStepsCounterNew;
280
282 BlockInfo_t** m_kList;
283
284 eC_UInt m_uiCurrentListSize;
285
287 eC_UInt m_uiFirstFreeIndexInList;
288
290 size_t m_uiUsedMemory;
291
293 size_t m_uiMaxMem;
294
296 size_t m_uiCurrentlyLargestObject;
297
299 size_t m_uiLargestObject;
300
302 eC_Int m_iAllocatedBlockCount;
303};
304
305#endif
Class CGUIMemLeakDetection for analyzing the use of memory and detecting the memory leaks.
Definition: GUIMemLeakDetection.h:63
const eC_UInt GetUsedMemory() const
friend void Guiliani_free(void *pMemory, const char *pFile, int iLine, const char *pFunction)
const eC_UInt GetMaxObject() const
void SetActive(const eC_Bool &bActive)
const eC_UInt GetLargestObject() const
friend void * Guiliani_malloc(size_t uiSize, const char *pFile, int iLine, const char *pFunction)
friend void Guiliani_deleteArray(void *pMemory, const char *pFile, int iLine, const char *pFunction)
friend void * Guiliani_newArray(size_t uiSize, const char *pFile, int iLine, const char *pFunction)
friend void * Guiliani_new(size_t uiSize, const char *pFile, int iLine, const char *pFunction)
friend void Guiliani_delete(void *pMemory, const char *pFile, int iLine, const char *pFunction)
static CGUIMemLeakDetection & GetInstance()
Definition: GUIMemLeakDetection.h:143
const eC_UInt GetCurrentlyLargestObject() const
friend void * Guiliani_realloc(void *pMemory, size_t uiSize, const char *pFile, int iLine, const char *pFunction)
void WriteResultsToFile(const eC_Char *sFilename="MemoryAnalysisResults.log", const eC_Bool &bAsTable=true)
bool operator==(const NSmartPtr::SharedPtr< C1 > &a, const NSmartPtr::SharedPtr< C2 > &b)
Definition: SharedPtr.h:240