class PMemoryHeap

Memory heap chacking class.

Public Classes

[more]enum Validation
Validation result

Public Methods

[more]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 ( void * ptr, const char * className, ostream * error )
Validate the memory pointer.
[more]static BOOL ValidateHeap ( ostream * error = NULL )
Validate all objects in memory.
[more]static BOOL SetIgnoreAllocations ( BOOL 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 DumpObjectsSince ( DWORD objectNumber )
Dump allocated objects.
[more]static void DumpObjectsSince ( DWORD objectNumber, ostream & strm )
Dump allocated objects.
[more]static void SetAllocationBreakpoint ( DWORD point )
Set break point allocation number.

Protected Methods

[more] PMemoryHeap ()
Initialise the memory checking subsystem.


Documentation

Memory heap chacking 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.
o PMemoryHeap()
Initialise the memory checking subsystem.

ostatic void* Allocate( size_t nSize, const char * file, int line, const char * className )
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.

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

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

ostatic void Deallocate( void * ptr, const char * className )
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.

oenum Validation
Validation result

ostatic Validation Validate( void * ptr, const char * className, ostream * error )
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)

ostatic BOOL ValidateHeap( ostream * error = NULL )
Validate all objects in memory. This effectively calls Validate() on every object in the heap.
Returns:
TRUE if every object in heap is Ok.

ostatic BOOL SetIgnoreAllocations( BOOL ignore )
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.

ostatic void DumpStatistics()
Get memory check system statistics. Dump statistics output to the default stream.

ostatic void DumpStatistics(ostream & strm)
Get memory check system statistics. Dump statistics output to the specified stream.
Parameters:
strm - Stream to output to

ostatic void DumpObjectsSince( DWORD objectNumber )
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:
objectNumber - Memory object to begin dump from.

ostatic void DumpObjectsSince( DWORD objectNumber, ostream & strm )
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:
objectNumber - Memory object to begin dump from.
strm - Stream to output dump

ostatic void SetAllocationBreakpoint( DWORD point )
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.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.