7.3 The Confidence Test

A console-based test program named 'HeapTest.exe' is supplied with the LeapHeap download. This multithreaded program makes large numbers of calls to HeapAlloc and HeapFree. HeapTest writes a characteristic pattern into the memory it allocates; before freeing it verifies that the pattern has not changed. In this way it is able to detect duplicate allocation of a memory area. HeapTest stops with a diagnostic message if any such error is detected. Running the program is of greatest value on multiprocessor machines, where correct thread synchronisation depends on more hardware than just the processor; faulty designs have occasionally been shipped.

A HeapTest run is divided into three phases. During the heap growth phase, 50 MB of allocations are made with no intervening frees. The proportion of allocations of a given size varies as the reciprocal of the cube of the size. Two samples are taken from this distribution and summed, to avoid large numbers of improbably small allocations such as one or two bytes. The mean allocation size is 40 bytes and the median allocation size 23 bytes. The second phase is heap reduction, where 20% of existing allocations are freed in order to produce something more like a mature, fragmented heap. The final phase is heap churn; about 33 million allocations and the same number of frees are performed. The allocation size, next operation (i.e. alloc or free) and the heap entry to free are all determined pseudo-randomly.

Throughout the three phases, eight threads are active, sharing the work to be done between them. The threads synchronise at the end of each phase.

The program executable resides in the LeapHeap directory, where because of the DLL search rules it runs with LeapHeap. A copy of the executable placed in another directory will run with the NT native heap, allowing performance comparisons.

The confidence test program is parameterisable by the command line switches /t (threads) and /s (size). Thus
HeapTest /s120 /t32
causes the program to allocate 120 MB of memory in the heap growth phase and spawn 32 threads to share the workload. Parameterisation allows comparisons between LeapHeap and the native heap for various combinations of concurrency and memory demand.