HeapAlloc

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

Syntax

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

A pointer to the allocated memory block if the function succeeds, NULL if the function fails

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 boundary, 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.

In RTSS build configurations, HeapAlloc differs from Windows in that it cannot allocate any amount of bytes greater than the amount of bytes a heap was created with. For example: in RTSS build configurations, if HeapAlloc attempted to allocate 4096 bytes of memory from a heap with only 2048 bytes, HeapAlloc would fail.

Requirements

Minimum Supported Version

RTX64 2013

API changes for RTX64 4.0

  • Changed DWORD Bytes to SIZE_T dwBytes
Header windows.h
Library Rtx_Rtss.lib

See Also: