Skip to content
Member Filters
Show Inherited
Show Protected
Show abstract
GR32_LowLevel🞂StackAllocFunction

StackAlloc

Allocates a temporary block of memory on the call stack and releases it.

Declaration ​

pascal
function StackAlloc(Size: Integer): Pointer; register;
procedure StackFree(P: Pointer); register;

Parameters ​

ParameterTypeDescription
SizeIntegerThe number of bytes to allocate on the stack.
PPointerPointer to the stack-allocated memory block to free.

Returns ​

TypeDescription
PointerReturns 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 ​

  • StackFree must be called in the exact same stack context as StackAlloc (not inside a nested subroutine or finally block).
  • Multiple StackFree calls must occur in reverse order of their corresponding StackAlloc calls.
  • If USESTACKALLOC is disabled or pure Pascal mode is active, StackAlloc transparently falls back to GetMem / FreeMem heap allocation.