MpHeap Sample: Multithreaded Heap Manager

Visual Studio 6.0

The MpHeap sample is a DLL that provides an implementation of multiple heaps and serializes access to the heaps. It will only work on Windows NT® 4.0 and later.

Many multithreaded applications that use the standard memory allocation routines pay a significant performance penalty when running on a multiprocessor machine. This is due to the serialization used by the default heap. On a multiprocessor machine, more than one thread may try to allocate memory simultaneously. One thread will block on the critical section guarding the heap. The other thread must then signal the critical section when it is finished to release the waiting thread. This adds significant overhead.

By providing multiple heaps, Mpheap.dll allows simultaneous operations on each heap. A thread on processor 0 can allocate memory from one heap at the same time that a thread on processor 1 is allocating from a different heap. The additional overhead in this DLL is offset by greatly reducing the number of times a thread must wait for heap access.

The Tmpheap sample is a simple program that demonstrates the functionality of Mpheap.dll.

Building SDK Samples

This sample uses the following keywords:

atoi; containing_record; createthread; deletecriticalsection; entercriticalsection; exit; fprintf; free; getcurrentthreadid; getlasterror; getsysteminfo; heapalloc; heapcompact; heapcreate; heapdestroy; heapfree; heaprealloc; heapvalidate; initializecriticalsection; interlockedcompareexchange; interlockedexchange; leavecriticalsection; localalloc; localfree; lookasideindexfromsize; malloc; mpheapalloc; mpheapcompact; mpheapcreate; mpheapdestroy; mpheapfree; mpheapgetstatistics; mpheaprealloc; mpheapvalidate; printf; processdelayedfreelist; rand; setlasterror; sleep; threadstartup; tryentercriticalsection; waitformultipleobjects; zeromemory

Show: