The Allocation menu tests and demonstrates different groups of allocation, reallocation and deallocation examples.
Each test is listed below with the source code location in the example application.
Click on the picture below to jump to the relevant sections:
Allocation menu C Runtime (C/C++) Heap submenu ...
Tests CRT heap allocation functions.
Allocate memory |
OnTestAllocatememory() Prompts for a number of bytes to allocate and how many times to do it. The memory is not deallocated. |
Reallocate memory |
OnTestReallocatememory() Prompts for a number of bytes to allocate and how many times to reallocate it, growing in size each time. The memory is not deallocated. |
Allocate using malloc() |
OnTestAllocateusingmalloc() Allocates 100 bytes of memory. The memory is not deallocated. |
Allocate using calloc() |
OnTestAllocateusingcalloc() Prompts for a number of bytes to allocate. The memory is not deallocated. |
Expand memory using _expand() |
OnTestExpandmemoryusingexpand() Allocated memory and then expands it using _expand(). Two more calls to expand the memory pass incorrect memory pointers. |
Shrink memory using _expand() |
OnTestShrinkmemoryusingexpand() Allocates memory and then shrinks it using _expand(). Two more calls to shrink the memory pass incorrect memory pointers. |
Allocate CObject |
OnTestAllocatecobject() Allocates a CWnd object. |
Allocate CString |
OnTestAllocatecstring() Allocates various TestClass objects freeing all but one. |
Multiple Allocation of CObject |
OnTestMultipleallocationofcobject() Allocates 5 CWnd objects. |
Multiple Allocation of CString |
OnTestMultipleallocationofcstring() Allocates 5 CString objects |
Multiple Allocation of CObject Leaving 1 |
OnTestMultipleallocationofcobjectLeaving1() Allocates 5 CWnd objects, then deletes 4 of them |
Multiple Allocation of CObject Leaving 2 |
OnTestMultipleallocationofcobjectLeaving2() Allocates 5 CWnd objects, then deletes 3 of them |
Multiple reallocation using malloc() and realloc() |
OnTestMultiplereallocation() Allocates and reallocates 3 pointers in a loop so the callstacks for each allocation are identical. |
Multi allocation, reallocation, deallocation using malloc, realloc, free |
OnMultiAlloc() Prompts for a number of allocations to make, each of random size. Allocations are freed |
Allocation menu Heap submenu ...
Tests Win32 heap functions HeapCreate(), HeapDestroy(), HeapAlloc(), HeapRealloc() and HeapFree().
Create Heap |
OnHandlesCreateheap() Create a heap using HeapCreate(). Do this first to enable the other tests. |
Destroy Heap |
OnHandlesDestroyheap() Destroy the heap created above. |
Allocate Memory |
OnHeapAllocatememory() Allocate 100 bytes on the heap |
Allocate and Reallocate |
OnHeapAllocateandreallocate() Allocate 100 bytes and then reallocate 200 bytes on the heap |
Allocate and Free |
OnHeapAllocateanddelete() Allocate 100 bytes on the heap and deallocate it |
Create Heap, Allocate Memory, Destroy Heap |
OnCreateHeapAllocateDestroy() Creates a heap, makes three allocations and destroys the heap. Allocations should not show as a leak. |
Allocation menu Local submenu ...
Tests Win32 local heap functions LocalAlloc(), LocalRealloc() and LocalFree().
Allocate Memory |
OnLocalAllocatememory() Allocate 4096 bytes using LocalAlloc(). |
Allocate and Reallocate |
OnLocalAllocateandreallocate() Allocates 4096 bytes and reallocates to 8192 bytes using LocalRealloc(). |
Allocate and Free |
OnLocalAllocateanddelete() Allocates 4096 bytes and deallocates with LocalFree(). |
Other functions that call LocalAlloc() |
OnLocalAllocFunctions() Allocate and leak memory using indirect calls to LocalAlloc(), eg FormatMessage(). |
Allocation menu Global submenu ...
Tests Win32 global heap functions GlobalAlloc(), GlobalRealloc() and GlobalFree().
Allocate Memory |
OnGlobalAllocatememory() Allocate 4096 bytes using GlobalAlloc(). |
Allocate and Reallocate |
OnGlobalAllocateandreallocate() Allocates 4096 bytes and reallocates to 8192 bytes using GlobalRealloc(). |
Allocate and Free |
OnGlobalAllocateanddelete() Allocates 4096 bytes and deallocates with GlobalFree(). |
Allocation menu Virtual submenu ...
Tests Win32 virtual memory allocation functions VirtualAlloc(), and VirtualFree().
Allocate |
OnAllocationVirtualAllocate() Commit virtual memory using VirtualAlloc(). |
Free |
OnAllocationVirtualFree() Decommit virtual memory using VirtualFree(). |
Allocation menu Virtual submenu ...
Tests Win32 virtual memory allocation functions VirtualAllocEx(), and VirtualFreeEx().
Allocate |
OnAllocationVirtualexAllocate() Commit virtual memory using VirtualAllocEx(). |
Free |
OnAllocationVirtualexFree() Decommit virtual memory using VirtualFreeEx(). |
Misc allocations |
OnMiscAllocations() Tests various functions including environment strings and array usage. Some allocations are leaked. |
NetApi allocations |
OnNetApiAllocations() Tests various functions including api buffer use. Some allocations are leaked. |
Printers |
OnTestPrinters() Opens and closes a printer and uses the printer notification api. Some allocations are leaked. |
|
Allocation menu Local submenu ...
Tests Win32 COM functions CoTaskMemAlloc(), CoTaskMemRealloc() and CoTaskMemFree().
Allocate Memory |
OnCotaskmemAllocatememory() Allocate 4000 bytes using CoTaskMemAlloc(). |
Allocate and Reallocate |
OnCotaskmemAllocateandreallocate() Allocates 4000 bytes and reallocates to 50000 bytes using CoTaskMemRealloc(). |
Allocate and Reallocate and Free |
OnCotaskmemAllocateandreallocateandfree() Allocates 4000 bytes, reallocates to 50000 and deallocates with CoTaskMemFree(). |
Allocate and Free |
OnCotaskmemAllocateanddelete() Allocate 4000 bytes, and deallocates with CoTaskMemFree(). |
Allocation menu IMalloc (IMallocSpy) ...
Tests the Win32 OLE memory allocation spy functions via IMallocSpy.
All these functions use CoGetMalloc() to get the OLE allocator.
Allocate Memory |
OnImallocAllocatememory() Allocate 4000 bytes using the OLE allocator. |
Allocate and Reallocate |
OnImallocAllocateandreallocate() Allocates 4000 bytes and reallocates to 50000 bytes. |
Allocate and Reallocate and Free |
OnImallocAllocateandreallocateandfree() Allocates 4000 bytes, reallocates to 50000 and then deallocates it. |
Allocate and Free |
OnImallocAllocateanddelete() Allocate 4000 bytes, and deallocates it. |
SysAllocString |
OnAllocationSysallocstring() Tests String use with SysAllocString(), SysReAllocString(), SysFreeString(), etc. Some allocations are leaked. |
CComVariant Test |
OnAllocationCcomvarianttest() Tests BSTR allocations use with Variant*() functions. Some allocations are leaked. |
CoTaskMemFree hooks (ole32) |
OnTestCoTaskMemFreeHooks() Tests various functions where memory is freed with CoTaskMemFree. |
SysAllocString special test |
OnAllocationSysallocstringspecialtest() Tests multiple allocations of zero length BSTRs. Allocations are leaked. |
AddRef / Release Test |
OnAllocationAddrefreleasetest() Tests reference counting using AddRef() and Release() Allocations are leaked. |
AddRef / Release Test |
OnAllocationAddrefreleasetestzerocount() As above but with additional attempt to Release() at a zero refcount. This may bring up the assertion dialog in the Debug versions |
Allocation menu Custom Allocator submenu ...
Demonstrates use of a custom heap via the API for C++ and C.
These tests require a version of the example application linked to the Memory Validator Stub.
The Debug or Release Non Link configurations will disable these menu options.
Allocate Memory |
OnCustomAllocatememory() Allocates memory using mvUserCustomAlloc() |
Allocate and Reallocate |
OnCustomAllocateandreallocate() Allocates and then reallocates using mvUserCustomReAlloc() |
Allocate and Reallocate and Free |
OnCustomAllocateandreallocateandfree() Allocates, reallocates and frees using mvUserCustomFree() |
Allocate and Free |
OnCustomAllocateanddelete() Allocates and frees memory |
Increase Reference Count |
OnAllocationCustomallocatorIncreasereferencecount() Demonstrates use of mvUserCustomRefCountIncrement() |
Decrease Reference Count |
OnAllocationCustomallocatorDecreasereferencecount() Demonstrates use of mvUserCustomRefCountDecrement() |
mvCollect(TRUE) |
OnMvCollectTRUE() Demonstrates use of mvSetCollect() |
mvCollect(FALSE) |
OnMvCollectFALSE() Demonstrates use of mvSetCollect() |
#define'd Allocator |
OnAllocationDefinedallocator() Demonstrates use of #define to define a wrapper macro around a standard memory allocation function. The Coverage tab is able to handle such cases. |
Test Many Hooks at once |
OnTestManyHooks() A convenience test that includes a selection of the tests above and more! |