Windows Logo

Microsoft Learn

HeapAlloc Function

HANDLE HeapCreate( DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize );

Parameters

flOptions

The heap allocation options. This parameter can be zero or the following value:

  • HEAP_GENERATE_EXCEPTIONS: Exceptions are generated when allocation fails. By default, when allocation fails, the function returns NULL.
dwInitialSize

The initial size of the heap, in bytes. If this parameter is 0, the initial size is set to the system's default size.

dwMaximumSize

The maximum size of the heap, in bytes. If this parameter is 0, the maximum size is the system's default size.

Return value

If the function succeeds, the return value is a handle to the newly created heap.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The HeapAlloc function allocates memory from a specified heap. The allocated memory is not initialized.

To free the memory allocated by HeapAlloc, use the HeapFree function.

It is recommended to use HeapAlloc over malloc for heap management in Windows applications as it provides more control and flexibility.

Requirements

SDK
Header: Windows.h
Library: Kernel32.lib
DLL: Kernel32.dll
Minimum supported client
Windows XP [desktop apps | UWP apps]

Minimum supported server
Windows Server 2003 [desktop apps | UWP apps]