![]() |
mksqlite
2.5
A MATLAB interface to SQLite
|
Helperclass for memory leak and access violation detection. More...
#include <heap_check.hpp>
Classes | |
struct | tagFooter |
Memory block footer (end marker) More... | |
struct | tagHeader |
Memory block header. More... | |
Public Member Functions | |
HeapCheck () | |
Standard ctor. | |
~HeapCheck () | |
Destructor. More... | |
void | Release () |
Releasing unfreed memory. More... | |
void | AddPtr (const tagHeader *ptr) |
Enqueues new memory block by header pointer ptr . | |
void | RemovePtr (const tagHeader *ptr) |
Removes memory block, identified by ptr without freeing it. More... | |
void * | New (size_t bytes, const char *file, const char *fcn, const char *notes, long nLine) |
Allocates a new block of memory with initialized header and footer. More... | |
void * | Realloc (void *ptr_old, size_t bytes, const char *file, const char *fcn, const char *notes, long nLine) |
Reallocates a block of memory allocated with New() More... | |
void | Free (void *ptr) |
Freeing space returned from New() or Realloc() | |
void | UpdateNotes (void *ptr, const char *notes) |
Update "notes" field in memory block header. | |
void | Walk (const char *text=NULL) |
Reporting walk through the linked memory list. More... | |
Static Public Member Functions | |
static size_t | GetHeaderSize () |
Returns the header size in bytes. | |
static int | isPtrAligned (const void *ptr) |
Checks if header pointer ptr is well aligned. More... | |
static int | VerifyPtr (const void *ptr) |
Checks if header pointer ptr is valid. More... | |
static void | RenderDesc (const tagHeader *header, char *lpBuffer, size_t szBuffer) |
Formatted output of memory block information (from its header) More... | |
Private Types | |
typedef std::vector< const tagHeader * > | vec_tagHeader |
Memory blocks linked list typedef. | |
Private Attributes | |
vec_tagHeader | m_mem_blocks |
Linked list of memory blocks used in module scope. | |
bool | flag_blocks_checked |
Flag will be set, when the block m_mem_blocks is released and checked. | |
Helperclass for memory leak and access violation detection.
Definition at line 52 of file heap_check.hpp.
struct HeapCheck::tagFooter |
Memory block footer (end marker)
The footer only holds a pointer to the memory block header and is used for consistence check only.
Definition at line 82 of file heap_check.hpp.
Class Members | ||
---|---|---|
tagHeader * | lpHeader | pointer to header of this memory block |
struct HeapCheck::tagHeader |
Memory block header.
Each memory block is surrounded by additional information: A preceding header stores who is responsible to this memory, some additional notes (comments) an a pointer to the end of the memory block (footer). By checking consitency of header and footer, one can test, if any close memory (write) accesses violation occures.
Definition at line 66 of file heap_check.hpp.
Class Members | ||
---|---|---|
long | lLineNumber | line number or 0 |
const char * | lpFilename | filename or NULL |
tagFooter * | lpFooter | pointer to footer, contiguous to memory block |
const char * | lpFunctionName | function name |
void * | lpMem | pointer to memory block (contiguous to this header space) |
const char * | lpNotes | pointer to further notes or NULL |
|
inline |
Destructor.
The destructor frees orphan memory space while reporting.
Definition at line 113 of file heap_check.hpp.
References Release().
|
inlinestatic |
Checks if header pointer ptr
is well aligned.
Headers are always aligned to HC_ALIGNMENT. Any other alignment inidcates an error.
Definition at line 170 of file heap_check.hpp.
References HC_ALIGNMENT.
Referenced by VerifyPtr().
|
inline |
Allocates a new block of memory with initialized header and footer.
[in] | bytes | Size of memory needed |
[in] | file | Source filename with calling function |
[in] | fcn | Name of calling function |
[in] | notes | Additional (optional) notes as comment for reporting function |
[in] | nLine | Line number of calling function |
Definition at line 239 of file heap_check.hpp.
References AddPtr(), HC_DOALIGN, HeapCheck::tagHeader::lLineNumber, HeapCheck::tagHeader::lpFilename, HeapCheck::tagHeader::lpFooter, HeapCheck::tagHeader::lpFunctionName, HeapCheck::tagFooter::lpHeader, HeapCheck::tagHeader::lpMem, and HeapCheck::tagHeader::lpNotes.
|
inline |
Reallocates a block of memory allocated with New()
[in] | ptr_old | Pointer returned by New() or NULL |
[in] | bytes | Size of memory needed |
[in] | file | Source filename with calling function |
[in] | fcn | Name replacement of calling function or NULL if not |
[in] | notes | Additional (optional) notes replacement as comment for reporting function or NULL if not |
[in] | nLine | Line number replacement of calling functionor 0 if not |
Definition at line 282 of file heap_check.hpp.
References AddPtr(), HC_DOALIGN, HeapCheck::tagHeader::lLineNumber, HeapCheck::tagHeader::lpFilename, HeapCheck::tagHeader::lpFooter, HeapCheck::tagHeader::lpFunctionName, HeapCheck::tagFooter::lpHeader, HeapCheck::tagHeader::lpMem, HeapCheck::tagHeader::lpNotes, MEM_REALLOC, RemovePtr(), and VerifyPtr().
|
inline |
Releasing unfreed memory.
Releasing memory, that is logged in the list of allocated memory blocks. Calling this function ensures that heap space is cleanly leaved. If any space is freed, a message will be displayed in MATLAB command window.
Definition at line 127 of file heap_check.hpp.
References MEM_FREE, PRINTF, and Walk().
Referenced by ~HeapCheck().
|
inline |
Removes memory block, identified by ptr
without freeing it.
Definition at line 215 of file heap_check.hpp.
Referenced by Free(), and Realloc().
|
inlinestatic |
Formatted output of memory block information (from its header)
[in] | header | Pointer to the header identifying the memory block |
[in,out] | lpBuffer | Buffer to hold the output (ASCII) |
[in] | szBuffer | Size of the buffer lpBuffer |
Definition at line 371 of file heap_check.hpp.
References HeapCheck::tagHeader::lpMem.
Referenced by Walk().
|
inlinestatic |
Checks if header pointer ptr
is valid.
Check if ptr
is well aligned and header and footer are consistent. If not, the was an access violation.
Definition at line 183 of file heap_check.hpp.
References HC_ASSERT, isPtrAligned(), HeapCheck::tagHeader::lpFooter, HeapCheck::tagFooter::lpHeader, and HeapCheck::tagHeader::lpMem.
Referenced by Free(), Realloc(), and UpdateNotes().
|
inline |
Reporting walk through the linked memory list.
[in] | text | Text which is additionally outputted to each memory block report, or NULL if not |
Definition at line 407 of file heap_check.hpp.
References PRINTF, and RenderDesc().
Referenced by mexFunction(), and Release().