GlobalAlloc

Syntax

HANDLE GlobalAlloc(wFlags,dwBytes)

This function allocates the number of bytes of memory specified by the dwBytes parameter from the global heap. The memory can be fixed or moveable, depending on the memory type specified by the wFlags parameter.

Parameter Type/Description  

wFlags WORD Specifies one or more flags that tell the GlobalAlloc function how to allocate the memory. It can be one or more of the following values:  
  Value Meaning
  GMEM_DDESHARE Allocates sharable memory. This is used for dynamic data exchange (DDE) only. Note, however, that Windows automatically discards memory allocated with this attribute when the application that allocated the memory terminates.
  GMEM_DISCARDABLE Allocates discardable memory. Can only be used with GMEM_MOVEABLE.
  GMEM_FIXED Allocates fixed memory.
  GMEM_MOVEABLE Allocates moveable memory. Cannot be used with GMEM_FIXED.
  GMEM_NOCOMPACT Does not compact or discard to satisfy the allocation request.
  GMEM_NODISCARD Does not discard to satisfy the allocation request.
  GMEM_NOT_BANKED Allocates non-banked memory. Cannot be used with GMEM_NOTIFY.
  GMEM_NOTIFY Calls the notification routine if the memory object is ever discarded.
  GMEM_ZEROINIT Initializes memory contents to zero.
Choose GMEM_FIXED or GMEM_MOVEABLE, and then combine others as needed by using the bitwise OR operator.  
dwBytes DWORD Specifies the number of bytes to be allocated.  

Return Value

The return value identifies the allocated global memory if the function is successful.
Otherwise, it is NULL.

Comments

If this function is successful, it allocates at least the amount requested. The actual amount allocated may be greater, and the application can use the entire amount. To determine the actual amount allocated, call the GlobalSize function.

The largest block of memory that an application can allocate is 1 MB in standard mode and 64 MB in 386 enhanced mode.