Dynamic memory allocation module. Provides the low-level allocation
and deallocation procedures used internally by NEW and DISPOSE.
PROCEDURE ALLOCATE(VAR p: ADDRESS; size: CARDINAL);
PROCEDURE DEALLOCATE(VAR p: ADDRESS; size: CARDINAL);
ALLOCATEallocatessizebytes and stores the pointer inp.DEALLOCATEfrees the memory atpand setsptoNIL.- The built-in
NEW(p)expands toALLOCATE(p, TSIZE(T))whereTis the base type of the pointerp. - The built-in
DISPOSE(p)expands toDEALLOCATE(p, TSIZE(T)). - Import
Storage(or at leastALLOCATE) to useNEW/DISPOSE.
MODULE StorageDemo;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
TYPE
NodePtr = POINTER TO Node;
Node = RECORD
value: INTEGER;
next: NodePtr;
END;
VAR p: NodePtr;
BEGIN
NEW(p);
p^.value := 42;
p^.next := NIL;
DISPOSE(p);
END StorageDemo.