PMemoryHeap Class Reference

Memory heap checking class. More...

#include <object.h>

List of all members.

Public Types

 Ok
 Bad
 Trashed
enum  Validation { Ok, Bad, Trashed }
 Validation result. More...

Public Member Functions

 PMemoryHeap ()
 Initialise the memory checking subsystem.
 ~PMemoryHeap ()

Static Public Member Functions

static void * Allocate (size_t nSize, const char *file, int line, const char *className)
 Allocate a memory block.
static void * Allocate (size_t count, size_t iSize, const char *file, int line)
 Allocate a memory block.
static void * Reallocate (void *ptr, size_t nSize, const char *file, int line)
 Change the size of an allocated memory block.
static void Deallocate (void *ptr, const char *className)
 Free a memory block.
static Validation Validate (const void *ptr, const char *className, ostream *error)
 Validate the memory pointer.
static PBoolean ValidateHeap (ostream *error=NULL)
 Validate all objects in memory.
static PBoolean SetIgnoreAllocations (PBoolean ignore)
 Ignore/Monitor allocations.
static void DumpStatistics ()
 Get memory check system statistics.
static void DumpStatistics (ostream &strm)
 Get memory check system statistics.
static void GetState (State &state)
static void DumpObjectsSince (const State &when)
 Dump allocated objects.
static void DumpObjectsSince (const State &when, ostream &strm)
 Dump allocated objects.
static void SetAllocationBreakpoint (DWORD point)
 Set break point allocation number.

Protected Types

 NoLeakPrint = 1
enum  Flags { NoLeakPrint = 1 }

Protected Member Functions

void * InternalAllocate (size_t nSize, const char *file, int line, const char *className)
Validation InternalValidate (const void *ptr, const char *className, ostream *error)
void InternalDumpStatistics (ostream &strm)
void InternalDumpObjectsSince (DWORD objectNumber, ostream &strm)

Protected Attributes

PBoolean isDestroyed
HeaderlistHead
HeaderlistTail
DWORD allocationRequest
DWORD firstRealObject
BYTE flags
char allocFillChar
char freeFillChar
DWORD currentMemoryUsage
DWORD peakMemoryUsage
DWORD currentObjects
DWORD peakObjects
DWORD totalObjects
ostream * leakDumpStream

Static Protected Attributes

static DWORD allocationBreakpoint

Classes

struct  Header
struct  State
class  Wrapper


Detailed Description

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.


Member Enumeration Documentation

enum PMemoryHeap::Flags [protected]

Enumerator:
NoLeakPrint 

enum PMemoryHeap::Validation

Validation result.

Enumerator:
Ok 
Bad 
Trashed 


Constructor & Destructor Documentation

PMemoryHeap::PMemoryHeap (  ) 

Initialise the memory checking subsystem.

PMemoryHeap::~PMemoryHeap (  ) 


Member Function Documentation

static void* PMemoryHeap::Allocate ( size_t  count,
size_t  iSize,
const char *  file,
int  line 
) [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.

Returns:
pointer to newly allocated memory block.
Parameters:
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 void* PMemoryHeap::Allocate ( size_t  nSize,
const char *  file,
int  line,
const char *  className 
) [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.

Returns:
pointer to newly allocated memory block.
Parameters:
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.

static void PMemoryHeap::Deallocate ( void *  ptr,
const char *  className 
) [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.

Parameters:
ptr  Pointer to memory block to deallocate.
className  Class name for deallocating function.

static void PMemoryHeap::DumpObjectsSince ( const State when,
ostream &  strm 
) [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.

Parameters:
when  Memory state to begin dump from.
strm  Stream to output dump

static void PMemoryHeap::DumpObjectsSince ( const State when  )  [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.

Parameters:
when  Memory state to begin dump from.

static void PMemoryHeap::DumpStatistics ( ostream &  strm  )  [static]

Get memory check system statistics.

Dump statistics output to the specified stream.

Parameters:
strm  Stream to output to

static void PMemoryHeap::DumpStatistics (  )  [static]

Get memory check system statistics.

Dump statistics output to the default stream.

static void PMemoryHeap::GetState ( State state  )  [static]

Parameters:
state  Memory state

void* PMemoryHeap::InternalAllocate ( size_t  nSize,
const char *  file,
int  line,
const char *  className 
) [protected]

void PMemoryHeap::InternalDumpObjectsSince ( DWORD  objectNumber,
ostream &  strm 
) [protected]

void PMemoryHeap::InternalDumpStatistics ( ostream &  strm  )  [protected]

Validation PMemoryHeap::InternalValidate ( const void *  ptr,
const char *  className,
ostream *  error 
) [protected]

static void* PMemoryHeap::Reallocate ( void *  ptr,
size_t  nSize,
const char *  file,
int  line 
) [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.

Returns:
pointer to reallocated memory block. Note this may {not} be the same as the pointer passed into the function.
Parameters:
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 void PMemoryHeap::SetAllocationBreakpoint ( DWORD  point  )  [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.

Parameters:
point  Allocation number to stop at.

static PBoolean PMemoryHeap::SetIgnoreAllocations ( PBoolean  ignore  )  [static]

Ignore/Monitor allocations.

Set internal flag so that allocations are not included in the memory leak check on program termination. Returns the previous state.

Parameters:
ignore  New flag for allocation ignoring.

static Validation PMemoryHeap::Validate ( const void *  ptr,
const char *  className,
ostream *  error 
) [static]

Validate the memory pointer.

The ptr parameter is validated as a currently allocated heap variable.

Returns:
Ok for pointer is in heap, Bad for pointer is not in the heap or Trashed if the pointer is in the heap but has overwritten the guard bytes before or after the actual data part of the memory block.
Parameters:
ptr  Pointer to memory block to check
className  Class name it should be.
error  Stream to receive error message (may be NULL)

static PBoolean PMemoryHeap::ValidateHeap ( ostream *  error = NULL  )  [static]

Validate all objects in memory.

This effectively calls Validate() on every object in the heap.

Returns:
true if every object in heap is Ok.
Parameters:
error  Stream to output, use default if NULL


Member Data Documentation

DWORD PMemoryHeap::allocationBreakpoint [static, protected]

DWORD PMemoryHeap::allocationRequest [protected]

char PMemoryHeap::allocFillChar [protected]

DWORD PMemoryHeap::currentMemoryUsage [protected]

DWORD PMemoryHeap::currentObjects [protected]

DWORD PMemoryHeap::firstRealObject [protected]

BYTE PMemoryHeap::flags [protected]

char PMemoryHeap::freeFillChar [protected]

PBoolean PMemoryHeap::isDestroyed [protected]

ostream* PMemoryHeap::leakDumpStream [protected]

Header* PMemoryHeap::listHead [protected]

Header* PMemoryHeap::listTail [protected]

DWORD PMemoryHeap::peakMemoryUsage [protected]

DWORD PMemoryHeap::peakObjects [protected]

DWORD PMemoryHeap::totalObjects [protected]


The documentation for this class was generated from the following file:
Generated on Fri Oct 14 01:44:12 2011 for PTLib by  doxygen 1.4.7