HeapAlloc

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

Syntax

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

Parameters

[in] hHeap

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

[in] 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.

[in] 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 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, the heap can become fragmented. 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 more bytes than the amount of bytes a heap was created with. For example, if HeapAlloc attempted to allocate 4096 bytes of memory from a heap with only 2048 bytes, It would fail.

Requirements

Minimum supported version Header Library

wRTOS 1.0 SDK

windows.h

wRTOS_rtss.lib

See Also: