\n
Microsoft Invisible Computing

DebugHeap Concrete Class

Debug heap, a wrapper for the system heap. Prepends/appends some check bytes to the actual data, to catch overruns and multi-free.

Implements IHeap

Methods

DHPQueryInterface implements IUnknown.QueryInterface
Source in dbg_heap.c

Determines which interfaces an object supports and returns a valid pointer to an interface.

DHPAddRef implements IUnknown.AddRef
Source in dbg_heap.c

Increments the reference count of the object.

DHPRelease implements IUnknown.Release
Source in dbg_heap.c

Decrements the reference count of an object. When the count goes to zero, the object is destroyed.

DHPAlloc implements IHeap.Alloc
Source in dbg_heap.c

Allocates a heap block of at least Size bytes from the given heap.

DHPRealloc implements IHeap.Realloc
Source in dbg_heap.c

Changes the size of a previously allocated memory block.

DHPFree implements IHeap.Free
Source in dbg_heap.c

Frees a block of memory previously allocated through a call to the IHeap.Alloc or IHeap.Realloc methods.

DHPSize implements IHeap.Size
Source in dbg_heap.c

Returns the usable size of the memory block pointed by pMem, a block that was allocated out of the given heap. Returns 0 if error.

DHPValidate implements IHeap.Validate
Source in dbg_heap.c

Validates the internal heap data structures. Checks the entire heap when pMem is NULL, otherwise verifies that the specified memory block is valid.

DHPExtract implements IHeap.Extract
Source in dbg_heap.c

Allocates memory at a specific address, from the given heap.

DHPStatus implements IHeap.Status
Source in dbg_heap.c

Returns status information about this heap

DHPCreateHeap implements IHeap.CreateHeap
Source in dbg_heap.c

Create a new heap instance, either through allocating memory from this or from implementation specific resources.

This heap implements a wrapper for the system heap (obtained through a call to CurrentHeap()). All calls are passed through, therefore the actual memory comes from the same place as before. The header/trailer will impose an overhead of at least 16 bytes to each memory allocation.

The implementation of the constructor overrides the CurrentHeap function, when it is called the first time. This means that CurrentHeap will henceforth return that same first heap, until it is destroyed. Further calls to the constructor will create nested debug heaps, which is probably an unnecessary overkill.

Internally, the heap maintains a few statistical counters that might be of interest to a developer. The number of calls to each method are recorded for instance. These counters can be looked at with a debugger.

You need to call CreateDebugHeap() immediately in your program, before anything gets allocated. For C++ this probably means that you need to wrap your actual main with something like this:

main()

{

PIHEAP Heap = CreateDebugHeap(0,max heap size,0);

int i = my_real_main(0,NULL);

Heap->Release();

return i;

}

©2006 Microsoft Corporation. All rights reserved. Terms of Use Privacy Statement Accessibility End User License Agreement