HLOCAL LocalAlloc(fuFlags, cbAlloc) | |||||
UINT fuFlags; | /* allocation attributes | */ | |||
UINT cbAlloc; | /* number of bytes to allocate | */ |
The LocalAlloc function allocates the specified number of bytes from the heap. In the flat 32-bit Win32 environment, there is no difference between the “local” heap and the “global” heap.
fuFlags
Specifies how to allocate memory. This parameter is some combination of the following values:
Value | Meaning |
LHND | ||
Combines the LMEM_MOVEABLE and LMEM_ZEROINIT flags. | ||
LMEM_DISCARDABLE | ||
The memory is discardable. | ||
LMEM_FIXED | ||
The memory is fixed. The LMEM_FIXED and LMEM_MOVEABLE flags cannot be combined. | ||
LMEM_MOVEABLE | ||
The memory is movable memory. The LMEM_FIXED and LMEM_MOVEABLE flags cannot be combined. | ||
LMEM_NOCOMPACT | ||
Does not compact or discard memory to satisfy the allocation request. | ||
LMEM_NODISCARD | ||
Does not discard memory to satisfy the allocation request. | ||
LMEM_ZEROINIT | ||
The memory contents are initialized to zero. | ||
LPTR | ||
Combines the LMEM_FIXED and LMEM_ZEROINIT flags. | ||
NONZEROLHND | ||
Same as the LMEM_MOVEABLE flag. | ||
NONZEROLPTR | ||
Same as the LMEM_FIXED flag. |
cbAlloc
Specifies the number of bytes to be allocated.
The return value identifies the newly allocated memory object, if the function is successful. Otherwise, it is NULL. Use the GetLastError function to obtain extended error information.
If LocalAlloc allocates movable memory, the return value is a handle to the memory. To access the memory, an application must use the LocalLock function to convert the handle to a pointer.
If LocalAlloc allocates fixed memory, the return value is a pointer to the memory. To access the memory, an application can simply cast the return value to a pointer.
If the heap does not contain sufficient free space to satisfy the request, this function returns NULL.
If this function is successful, it allocates at least the amount requested. The actual amount allocated may be greater. To determine the actual amount allocated, use the LocalSize function.
LocalLock, LocalSize