Next: Operations for Integer and Ordinal Types, Previous: Accessing Command Line Arguments, Up: Library Routines
Besides the standard New and Dispose routines, GPC
also allows BP style dynamic memory management with GetMem
and FreeMem
:
GetMem (MyPtr, 1024); FreeMem (MyPtr, 1024);
One somehow strange feature of Borland is not supported:
You cannot free parts of a variable with FreeMem
, while the
rest is still used and can be freed later by another FreeMem
call:
program PartialFreeMemDemo; type Vector = array [0 .. 1023] of Integer; VecPtr = ^Vector; var p, q: VecPtr; begin GetMem (p, 1024 * SizeOf (Integer)); q := VecPtr (@p^[512]); { ... } FreeMem (p, 512 * SizeOf (Integer)); { ... } FreeMem (q, 512 * SizeOf (Integer)); end.