GlobalAlloc
GlobalAlloc is a Windows API function that allocates memory from the process’s global heap. It returns a handle to the allocated block (an HGLOBAL) or NULL on failure. The function is part of the legacy Global/Local memory management API that originated in 16-bit Windows and is retained mainly for backward compatibility and for use with certain APIs such as the clipboard.
The function has the signature HGLOBAL GlobalAlloc(UINT uFlags, SIZE_T dwBytes). The uFlags parameter specifies the allocation
Accessing the memory depends on the flags. If GMEM_MOVEABLE is specified, GlobalAlloc returns a movable handle;
Typical usage pattern: h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 1024); if (h) { p = GlobalLock(h); / use p / GlobalUnlock(h); GlobalFree(h); }
Notes: GlobalAlloc is largely obsolete for new code; modern alternatives such as HeapAlloc or VirtualAlloc are