PTLib
Version 2.18.8
|
Memory heap checking class. More...
#include <object.h>
Classes | |
struct | Header |
struct | State |
Public Types | |
enum | Validation { Ok, Bad, Trashed, Corrupt, Inactive } |
Validation result. More... | |
typedef unsigned | alloc_t |
Public Member Functions | |
~PMemoryHeap () | |
Static Public Member Functions | |
static void * | Allocate (size_t nSize, const char *file, int line, const char *className) |
Allocate a memory block. More... | |
static void * | Allocate (size_t count, size_t iSize, const char *file, int line) |
Allocate a memory block. More... | |
static void * | Reallocate (void *ptr, size_t nSize, const char *file, int line) |
Change the size of an allocated memory block. More... | |
static void | Deallocate (void *ptr, const char *className) |
Free a memory block. More... | |
static Validation | Validate (const void *ptr, const char *className, ostream *error) |
Validate the memory pointer. More... | |
static PBoolean | ValidateHeap (ostream *error=NULL) |
Validate all objects in memory. More... | |
static PBoolean | SetIgnoreAllocations (PBoolean ignore) |
Ignore/Monitor allocations. More... | |
static void | DumpStatistics () |
Get memory check system statistics. More... | |
static void | DumpStatistics (ostream &strm) |
Get memory check system statistics. More... | |
static void | GetState (State &state) |
static void | DumpObjectsSince (const State &when) |
Dump allocated objects. More... | |
static void | DumpObjectsSince (const State &when, ostream &strm) |
Dump allocated objects. More... | |
static void | SetAllocationBreakpoint (alloc_t point) |
Set break point allocation number. More... | |
Protected Types | |
enum | Flags { NoLeakPrint = 1 } |
enum | { e_Destroyed =-1, e_Disabled, e_TrackOnly, e_Active } |
Protected Member Functions | |
PMemoryHeap () | |
Initialise the memory checking subsystem. More... | |
void * | InternalAllocate (size_t nSize, const char *file, int line, const char *className, bool zeroFill) |
void * | InternalReallocate (void *ptr, size_t nSize, const char *file, int line) |
void | InternalDeallocate (void *ptr, const char *className) |
Validation | InternalValidate (const void *ptr, const char *className, ostream *error) |
bool | InternalValidateHeap (ostream *error) |
void | InternalDumpStatistics (ostream &strm) |
void | InternalDumpObjectsSince (DWORD objectNumber, ostream &strm) |
void | Lock () |
void | Unlock () |
Static Protected Member Functions | |
static PMemoryHeap & | GetInstance () |
Protected Attributes | |
enum PMemoryHeap:: { ... } | m_state |
Header * | m_listHead |
Header * | m_listTail |
alloc_t | m_allocationRequest |
alloc_t | m_allocationBreakpoint |
alloc_t | m_firstRealObject |
uint8_t | m_flags |
char | m_allocFillChar |
char | m_freeFillChar |
size_t | m_currentMemoryUsage |
size_t | m_peakMemoryUsage |
alloc_t | m_currentObjects |
alloc_t | m_peakObjects |
alloc_t | m_totalObjects |
ostream * | m_leakDumpStream |
Memory heap checking class.
This class implements the memory heap checking and validation functions. It maintains lists of allocated block so that memory leaks can be detected. It also initialises memory on allocation and deallocation to help catch errors involving the use of dangling pointers.
typedef unsigned PMemoryHeap::alloc_t |
|
protected |
|
protected |
Initialise the memory checking subsystem.
PMemoryHeap::~PMemoryHeap | ( | ) |
|
static |
Allocate a memory block.
This allocates a new memory block and keeps track of it. The memory block is filled with the value in the allocFillChar
member variable to help detect uninitialised structures.
nSize | Number of bytes to allocate. |
file | Source file name for allocating function. |
line | Source file line for allocating function. |
className | Class name for allocating function. |
Referenced by operator new(), and operator new[]().
|
static |
Allocate a memory block.
This allocates a new memory block and keeps track of it. The memory block is filled with the value in the allocFillChar
member variable to help detect uninitialised structures.
count | Number of items to allocate. |
iSize | Size in bytes of each item. |
file | Source file name for allocating function. |
line | Source file line for allocating function. |
|
static |
Free a memory block.
The memory is deallocated, a warning is displayed if it was never allocated. The block of memory is filled with the value in the freeFillChar
member variable.
ptr | Pointer to memory block to deallocate. |
className | Class name for deallocating function. |
|
static |
Dump allocated objects.
Dump ojects allocated and not deallocated since the specified object number. This would be a value returned by the GetAllocationRequest()
function.
Output is to the default stream.
when | Memory state to begin dump from. |
|
static |
Dump allocated objects.
Dump ojects allocated and not deallocated since the specified object number. This would be a value returned by the GetAllocationRequest()
function.
when | Memory state to begin dump from. |
strm | Stream to output dump |
|
static |
Get memory check system statistics.
Dump statistics output to the default stream.
|
static |
Get memory check system statistics.
Dump statistics output to the specified stream.
strm | Stream to output to |
|
staticprotected |
|
static |
state | Memory state |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
static |
Change the size of an allocated memory block.
This allocates a new memory block and keeps track of it. The memory block is filled with the value in the allocFillChar
member variable to help detect uninitialised structures.
ptr | Pointer to memory block to reallocate. |
nSize | New number of bytes to allocate. |
file | Source file name for allocating function. |
line | Source file line for allocating function. |
|
static |
Set break point allocation number.
Set the allocation request number to cause an assert. This allows a developer to cause a halt in a debugger on a certain allocation allowing them to determine memory leaks allocation point.
point | Allocation number to stop at. |
Referenced by PMemoryAllocationBreakpoint::PMemoryAllocationBreakpoint().
Ignore/Monitor allocations.
Set internal flag so that allocations are not included in the memory leak check on program termination. Returns the previous state.
ignore | New flag for allocation ignoring. |
Referenced by PMemoryHeapIgnoreAllocationsForScope::~PMemoryHeapIgnoreAllocationsForScope().
|
protected |
|
static |
Validate the memory pointer.
The ptr
parameter is validated as a currently allocated heap variable.
ptr | Pointer to memory block to check |
className | Class name it should be. |
error | Stream to receive error message (may be NULL) |
Referenced by PSingleton< Type, atomic< unsigned >, Creator >::PSingleton().
|
static |
Validate all objects in memory.
This effectively calls Validate() on every object in the heap.
error | Stream to output, use default if NULL |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
enum { ... } PMemoryHeap::m_state |
|
protected |