en:docs:win16:api:kernel:localalloc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en:docs:win16:api:kernel:localalloc [2026/02/25 08:46] prokusheven:docs:win16:api:kernel:localalloc [2026/02/25 08:48] (current) prokushev
Line 4: Line 4:
  
 ===== Brief ===== ===== Brief =====
 +
 Allocates a block of memory from the local heap of the current data segment. Allocates a block of memory from the local heap of the current data segment.
  
 ===== Syntax ===== ===== Syntax =====
-<code c>HLOCAL WINAPI LocalAlloc(+<code c> 
 +HLOCAL WINAPI LocalAlloc(
 UINT uFlags, UINT uFlags,
 UINT uBytes UINT uBytes
-);</code>+); 
 +</code>
  
 ===== Parameters ===== ===== Parameters =====
  
-uFlags – Allocation attributes. Common flags: +  * uFlags – Allocation attributes. Common flags: 
- +    LMEM_FIXED (0x0000) – Allocates fixed memory; the return value is a pointer. 
-LMEM_FIXED (0x0000) – Allocates fixed memory; the return value is a pointer. +    LMEM_MOVEABLE (0x0002) – Allocates movable memory; returns a handle. 
- +    LMEM_ZEROINIT (0x0040) – Initializes the memory to zero. 
-LMEM_MOVEABLE (0x0002) – Allocates movable memory; returns a handle. +    LMEM_DISCARDABLE (0x0F00) – Makes the block discardable (only with LMEM_MOVEABLE). 
- +    LMEM_NOCOMPACT (0x0010) – Prevents heap compaction for this allocation. 
-LMEM_ZEROINIT (0x0040) – Initializes the memory to zero. +    LMEM_NODISCARD (0x0020) – Prevents discarding of other blocks.
- +
-LMEM_DISCARDABLE (0x0F00) – Makes the block discardable (only with LMEM_MOVEABLE). +
- +
-LMEM_NOCOMPACT (0x0010) – Prevents heap compaction for this allocation. +
- +
-LMEM_NODISCARD (0x0020) – Prevents discarding of other blocks.+
  
 Shorthands: LHND (LMEM_MOVEABLE | LMEM_ZEROINIT), LPTR (LMEM_FIXED | LMEM_ZEROINIT). Shorthands: LHND (LMEM_MOVEABLE | LMEM_ZEROINIT), LPTR (LMEM_FIXED | LMEM_ZEROINIT).
  
-uBytes – Number of bytes to allocate. If zero and LMEM_MOVEABLE is set, returns a handle to a discarded object.+  * uBytes – Number of bytes to allocate. If zero and LMEM_MOVEABLE is set, returns a handle to a discarded object.
  
 ===== Return Value ===== ===== Return Value =====
Line 40: Line 37:
 ===== Notes ===== ===== Notes =====
  
-For movable blocks, use LocalLock to obtain a pointer before accessing the memory. +  * For movable blocks, use LocalLock to obtain a pointer before accessing the memory. 
- +  The internal lock count of a new block is zero.
-The internal lock count of a new block is zero.+
  
 ===== Example Code ===== ===== Example Code =====
 ==== C Binding ==== ==== C Binding ====
-<code c>HLOCAL hMem = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 1024); +<code c> 
-HLOCAL hMem2 = LocalAlloc(LHND, 1024);</code>+HLOCAL hMem = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 1024); 
 +HLOCAL hMem2 = LocalAlloc(LHND, 1024); 
 +</code>
 ==== MASM Binding ==== ==== MASM Binding ====
-<code asm>push 0042h ; LMEM_MOVEABLE | LMEM_ZEROINIT+<code asm> 
 +push 0042h ; LMEM_MOVEABLE | LMEM_ZEROINIT
 push 0400h ; 1024 bytes push 0400h ; 1024 bytes
-call LocalAlloc</code>+call LocalAlloc 
 +</code>
  
 ===== See also ===== ===== See also =====
  
 [[LocalReAlloc]] [[LocalReAlloc]]
- 
 [[LocalFree]] [[LocalFree]]
- 
 [[LocalLock]] [[LocalLock]]
- 
- 
  
 {{page>en:templates:win16}} {{page>en:templates:win16}}