HeapAlloc

HeapAlloc allocates a block of memory from a heap. The allocated memory is not movable.

Syntax

Copy
LPVOID HeapAlloc(
    HANDLE hHeap,
    DWORD dwFlags,
    SIZE_T dwBytes
);

Parameters

hHeap

The heap from which the memory will be allocated. This parameter is a handle returned by GetProcessHeap.

Flags

The controllable aspects of heap allocation. You can specify the following flag:

Value Meaning
HEAP_ZERO_MEMORY The allocated memory will be initialized to zero.

Bytes

The number of bytes to be allocated.

Return Value

If the function succeeds, it returns a pointer to the allocated memory block. If the function fails, it returns NULL.

Remarks

If HeapAlloc succeeds, it allocates at least the amount of memory requested. If the actual amount allocated is greater than the amount requested, because it is rounded to page boundry, the process can use the entire amount. To determine the actual size of the allocated block, use HeapSize.

To free a block of memory allocated by HeapAlloc, use HeapFree. Memory allocated by HeapAlloc is not movable. Since the memory is not movable, it is possible for the heap to become fragmented. Note that if HEAP_ZERO_MEMORY is not specified, the allocated memory may not be initialized to zero.

Requirements

Minimum supported version Header Library

eRTOS 1.0 SDK

windows.h rtkrnl.lib

See Also: