Declaration ​
pascal
function StackAlloc(Size: Integer): Pointer; register;
procedure StackFree(P: Pointer); register;Parameters ​
| Parameter | Type | Description |
|---|---|---|
Size | Integer | The number of bytes to allocate on the stack. |
P | Pointer | Pointer to the stack-allocated memory block to free. |
Returns ​
| Type | Description |
|---|---|
Pointer | Returns a pointer to the stack-allocated memory buffer. |
Description ​
StackAlloc provides rapid allocation of small temporary memory blocks directly from the call stack by adjusting the stack pointer. This achieves allocation performance equivalent to local variables while allowing dynamic runtime buffer sizing.
StackFree releases the memory allocated by StackAlloc.
Remarks ​
StackFreemust be called in the exact same stack context asStackAlloc(not inside a nested subroutine orfinallyblock).- Multiple
StackFreecalls must occur in reverse order of their correspondingStackAlloccalls. - If
USESTACKALLOCis disabled or pure Pascal mode is active,StackAlloctransparently falls back toGetMem/FreeMemheap allocation.