LocalAlloc

2.x

  HLOCAL LocalAlloc(fuAllocFlags, fuAlloc)    
  UINT fuAllocFlags; /* allocation attributes, */  
  UINT fuAlloc; /* number of bytes to allocate */

The LocalAlloc function allocates the specified number of bytes from the local heap.

Parameters

fuAllocFlags

Specifies how to allocate memory. This parameter can be a combination of the following values:

Value Meaning

LHND Combines the LMEM_MOVEABLE and LMEM_ZEROINIT flags.
LMEM_DISCARDABLE Allocates discardable memory.
LMEM_FIXED Allocates fixed memory. The LMEM_FIXED and LMEM_MOVEABLE flags cannot be combined.
LMEM_MOVEABLE Allocates 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 Initializes memory contents 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.

fuAlloc

Specifies the number of bytes to be allocated.

Return Value

The return value is the instance handle of the newly allocated local memory object, if the function is successful. Otherwise, it is NULL.

Comments

If LocalAlloc allocates movable memory, the return value is a local handle of 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.

Fixed memory will be slightly faster than movable memory. If memory will be allocated and freed without an intervening local allocation or reallocation, then the memory should be allocated as fixed.

If this function is successful, it allocates at least the amount requested. If the amount allocated is greater than the amount requested, the application can use the entire amount. To determine the size of a local memory object, an application can use the LocalSize function.

To free a local memory object, an application should use the LocalFree function. To change the size or attributes of an allocated memory object, an application can use the LocalReAlloc function.

See Also

LocalFree, LocalLock, LocalReAlloc, LocalSize, LocalUnlock