Compartir a través de


CWin32Heap::CWin32Heap

The constructor.

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

Parameters

  • hHeap
    An existing heap object.

  • dwFlags
    Flags used in creating the heap.

  • nInitialSize
    The initial size of the heap.

  • nMaxSize
    The maximum size of the heap.

Remarks

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.

Requirements

Header: atlmem.h

See Also

Reference

CWin32Heap Class

HeapCreate

Other Resources

CWin32Heap Members