HeapCreate

  HANDLE HeapCreate(fdwHeap, cbInitial, cbMaximum)    
  DWORD fdwHeap;    
  DWORD cbInitial;    
  DWORD cbMaximum;    

The HeapCreate function creates a heap with the specified size.

Parameters

fdwHeap

Specifies optional behaviors for the heap being created. This parameter may have the following value:

Value Meaning

HEAP_SERIALIZE  
  All access to the heap will be serialized within the current process. This flag prevents two threads from simultaneously accessing the heap with the same heap handle (see the Comments section for more details).

cbInitial

Specifies the initial size of the heap (in bytes).

cbMaximum

Specifies the maximum size the heap can grow to in order to satisfy HeapAlloc requests. If this parameter is zero, the size of the heap is limited by available memory.

Return Value

If the function is successful, the return value is a handle to the newly created heap. Otherwise, the return value is NULL. Use the GetLastError function to obtain extended error information.

Comment

Because the system allocates heap support structures out of the heap, all of the allocated heap will not be available to the application. For example, a 64K allocation request from a 64K heap may fail because of the system overhead.

The HEAP_SERIALIZE flag causes mutual exclusion on the heap. Without this flag, the heap can be corrupted if two threads make simultaneous Heap calls using the same heap handle. It is safe to leave this flag off if the heap will not be accessed by more than one thread at the same time. This would be true if

1.The application has only one thread.

2.The application has multiple threads, but this heap belongs to a single thread.

3.The application has multiple threads and uses another form of mutual exclusion. For example, the heap may be part of a larger data structure that uses an Event to keep multiple threads from accessing it at the same time.

See Also

HeapAlloc, HeapDestroy