Export (0) Print
Expand All


The constructor.

CWin32Heap( ) throw( ); 
   HANDLE hHeap 
) throw( );
   DWORD dwFlags,
   size_t nInitialSize,
   size_t nMaxSize = 0 



An existing heap object.


Flags used in creating the heap.


The initial size of the heap.


The maximum size of the heap.

Before allocating memory, it is necessary to provide the CWin32Heap object with a valid heap handle. The simplest way to achieve this is to use the process heap:

CWin32Heap MyHeap(GetProcessHeap());

It is also possible to supply an existing heap handle to the constructor, in which case the new object does not take over ownership of the heap. The original heap handle will still be valid when the CWin32Heap object is deleted.

An existing heap can also be attached to the new object, using CWin32Heap::Attach.

If a heap is required where operations are all performed from a single thread, the best way is to create the object as follows:

CWin32Heap MyHeap(HEAP_NO_SERIALIZE, SomeInitialSize);

The parameter HEAP_NO_SERIALIZE specifies that mutual exclusion will not be used when the heap functions allocate and free memory, with an according increase in performance.

The third parameter defaults to 0, which allows the heap to grow as required. See HeapCreate for an explanation of the memory sizes and flags.

Community Additions

© 2015 Microsoft