Please enable JavaScript to view this site.

Memory Validator Help

 

The allocation menu

 

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.

 

seeAlsoHow to use these examples

 

Click on the picture below to jump to the relevant sections:

 

interactive

example-app-allocation-menu

 

 

Allocation menu : C Runtime (C/C++) Heap

 

menu Allocation menu instructionStep C Runtime (C/C++) Heap submenu instructionStep ...

 

Tests CRT heap allocation functions.

 

instructionStep Allocate memory

OnTestAllocatememory()

Prompts for a number of bytes to allocate and how many times to do it.

The memory is not deallocated.

instructionStep 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.

instructionStep Allocate using malloc()

OnTestAllocateusingmalloc()

Allocates 100 bytes of memory.

The memory is not deallocated.

instructionStep Allocate using calloc()

OnTestAllocateusingcalloc()

Prompts for a number of bytes to allocate.

The memory is not deallocated.

instructionStep Expand memory using _expand()

OnTestExpandmemoryusingexpand()

Allocated memory and then expands it using _expand().

Two more calls to expand the memory pass incorrect memory pointers.

instructionStep Shrink memory using _expand()

OnTestShrinkmemoryusingexpand()

Allocates memory and then shrinks it using _expand().

Two more calls to shrink the memory pass incorrect memory pointers.

instructionStep Allocate CObject

OnTestAllocatecobject()

Allocates a CWnd object.

instructionStep Allocate CString

OnTestAllocatecstring()

Allocates various TestClass objects freeing all but one.

instructionStep Multiple Allocation of CObject

OnTestMultipleallocationofcobject()

Allocates 5 CWnd objects.

instructionStep Multiple Allocation of CString

OnTestMultipleallocationofcstring()

Allocates 5 CString objects

instructionStep Multiple Allocation of CObject Leaving 1

OnTestMultipleallocationofcobjectLeaving1()

Allocates 5 CWnd objects, then deletes 4 of them

instructionStep Multiple Allocation of CObject Leaving 2

OnTestMultipleallocationofcobjectLeaving2()

Allocates 5 CWnd objects, then deletes 3 of them

instructionStep Multiple reallocation using malloc() and realloc()

OnTestMultiplereallocation()

Allocates and reallocates 3 pointers in a loop so the callstacks for each allocation are identical.

instructionStep 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

 

menu Allocation menu instructionStep Heap submenu instructionStep ...

 

Tests Win32 heap functions HeapCreate(), HeapDestroy(), HeapAlloc(), HeapRealloc() and HeapFree().

 

instructionStep Create Heap

OnHandlesCreateheap()

Create a heap using HeapCreate().

Do this first to enable the other tests.

instructionStep Destroy Heap

OnHandlesDestroyheap()

Destroy the heap created above.

instructionStep Allocate Memory

OnHeapAllocatememory()

Allocate 100 bytes on the heap

instructionStep Allocate and Reallocate

OnHeapAllocateandreallocate()

Allocate 100 bytes and then reallocate 200 bytes on the heap

instructionStep Allocate and Free

OnHeapAllocateanddelete()

Allocate 100 bytes on the heap and deallocate it

instructionStep 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

 

menu Allocation menu instructionStep Local submenu instructionStep ...

 

Tests Win32 local heap functions LocalAlloc(), LocalRealloc() and LocalFree().

 

instructionStep Allocate Memory

OnLocalAllocatememory()

Allocate 4096 bytes using LocalAlloc().

instructionStep Allocate and Reallocate

OnLocalAllocateandreallocate()

Allocates 4096 bytes and reallocates to 8192 bytes using LocalRealloc().

instructionStep Allocate and Free

OnLocalAllocateanddelete()

Allocates 4096 bytes and deallocates with LocalFree().

instructionStep Other functions that call LocalAlloc()

OnLocalAllocFunctions()

Allocate and leak memory using indirect calls to LocalAlloc(), eg FormatMessage().

 

 

Allocation menu :  Global

 

menu Allocation menu instructionStep Global submenu instructionStep ...

 

Tests Win32 global heap functions GlobalAlloc(), GlobalRealloc() and GlobalFree().

 

instructionStep Allocate Memory

OnGlobalAllocatememory()

Allocate 4096 bytes using GlobalAlloc().

instructionStep Allocate and Reallocate

OnGlobalAllocateandreallocate()

Allocates 4096 bytes and reallocates to 8192 bytes using GlobalRealloc().

instructionStep Allocate and Free

OnGlobalAllocateanddelete()

Allocates 4096 bytes and deallocates with GlobalFree().

 

 

Allocation menu :  Virtual

 

menu Allocation menu instructionStep Virtual submenu instructionStep ...

 

Tests Win32 virtual memory allocation functions VirtualAlloc(), and VirtualFree().

 

instructionStep Allocate

OnAllocationVirtualAllocate()

Commit virtual memory using VirtualAlloc().

instructionStep Free

OnAllocationVirtualFree()

Decommit virtual memory using VirtualFree().

 

 

Allocation menu :  VirtualEx

 

menu Allocation menu instructionStep Virtual submenu instructionStep ...

 

Tests Win32 virtual memory allocation functions VirtualAllocEx(), and VirtualFreeEx().

 

instructionStep Allocate

OnAllocationVirtualexAllocate()

Commit virtual memory using VirtualAllocEx().

instructionStep Free

OnAllocationVirtualexFree()

Decommit virtual memory using VirtualFreeEx().

 

 

Allocation menu :  Misc allocations

 

menu Misc allocations

OnMiscAllocations()

Tests various functions including environment strings and array usage.

Some allocations are leaked.

 

 

Allocation menu :  NetApi allocations

 

menu NetApi allocations

OnNetApiAllocations()

Tests various functions including api buffer use.

Some allocations are leaked.

 

 

Allocation menu :  Printers

 

menu Printers

OnTestPrinters()

Opens and closes a printer and uses the printer notification api.

Some allocations are leaked.

 

 

 

Allocation menu :  COM (CoTaskMemAlloc)

 

menu Allocation menu instructionStep Local submenu instructionStep ...

 

Tests Win32 COM functions CoTaskMemAlloc(), CoTaskMemRealloc() and CoTaskMemFree().

 

instructionStep Allocate Memory

OnCotaskmemAllocatememory()

Allocate 4000 bytes using CoTaskMemAlloc().

instructionStep Allocate and Reallocate

OnCotaskmemAllocateandreallocate()

Allocates 4000 bytes and reallocates to 50000 bytes using CoTaskMemRealloc().

instructionStep Allocate and Reallocate and Free

OnCotaskmemAllocateandreallocateandfree()

Allocates 4000 bytes, reallocates to 50000 and deallocates with CoTaskMemFree().

instructionStep Allocate and Free

OnCotaskmemAllocateanddelete()

Allocate 4000 bytes, and deallocates with CoTaskMemFree().

 

 

Allocation menu :  IMalloc (IMallocSpy)

 

menu Allocation menu instructionStep IMalloc (IMallocSpy) instructionStep ...

 

Tests the Win32 OLE memory allocation spy functions via IMallocSpy.

 

All these functions use CoGetMalloc() to get the OLE allocator.

 

instructionStep Allocate Memory

OnImallocAllocatememory()

Allocate 4000 bytes using the OLE allocator.

instructionStep Allocate and Reallocate

OnImallocAllocateandreallocate()

Allocates 4000 bytes and reallocates to 50000 bytes.

instructionStep Allocate and Reallocate and Free

OnImallocAllocateandreallocateandfree()

Allocates 4000 bytes, reallocates to 50000 and then deallocates it.

instructionStep Allocate and Free

OnImallocAllocateanddelete()

Allocate 4000 bytes, and deallocates it.

 

 

Allocation menu :  SysAllocString

 

menu SysAllocString

OnAllocationSysallocstring()

Tests String use with SysAllocString(), SysReAllocString(), SysFreeString(), etc.

Some allocations are leaked.

 

 

Allocation menu :  CComVariant Test

 

menu CComVariant Test

OnAllocationCcomvarianttest()

Tests BSTR allocations use with Variant*() functions.

Some allocations are leaked.

 

 

Allocation menu :  CoTaskMemFree hooks

 

menu CoTaskMemFree hooks (ole32)

OnTestCoTaskMemFreeHooks()

Tests various functions where memory is freed with CoTaskMemFree.

 

 

Allocation menu :  SysAllocString special test

 

menu SysAllocString special test

OnAllocationSysallocstringspecialtest()

Tests multiple allocations of zero length BSTRs.

Allocations are leaked.

 

 

Allocation menu :  AddRef/Release Tests

 

menu AddRef / Release Test

OnAllocationAddrefreleasetest()

Tests reference counting using AddRef() and Release()

Allocations are leaked.

menu AddRef / Release Test
  (with zero refcount error)

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

 

menu Allocation menu instructionStep Custom Allocator submenu instructionStep ...

 

Demonstrates use of a custom heap  via the API for C++ and C.

 

note 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.

 

instructionStep Allocate Memory

OnCustomAllocatememory()

Allocates memory using mvUserCustomAlloc()

instructionStep Allocate and Reallocate

OnCustomAllocateandreallocate()

Allocates and then reallocates using mvUserCustomReAlloc()

instructionStep Allocate and Reallocate and Free

OnCustomAllocateandreallocateandfree()

Allocates, reallocates and frees using mvUserCustomFree()

instructionStep Allocate and Free

OnCustomAllocateanddelete()

Allocates and frees memory

instructionStep Increase Reference Count

OnAllocationCustomallocatorIncreasereferencecount()

Demonstrates use of mvUserCustomRefCountIncrement()

instructionStep Decrease Reference Count

OnAllocationCustomallocatorDecreasereferencecount()

Demonstrates use of mvUserCustomRefCountDecrement()

instructionStep mvCollect(TRUE)

OnMvCollectTRUE()

Demonstrates use of mvSetCollect()

instructionStep mvCollect(FALSE)

OnMvCollectFALSE()

Demonstrates use of mvSetCollect()

 

 

Allocation menu :  #define'd Allocator

 

menu #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.

 

 

Allocation menu :  Test Many Hooks at once

 

menu Test Many Hooks at once

OnTestManyHooks()

A convenience test that includes a selection of the tests above and more!