Heap management may be done in one of two ways in the Pascal/MT+ system. The first is to use the ISO standard routines as they are implemented in FULLHEAP.ERL. In this module, the NEW routine uses a standard heap. Dynamic data is allocated into the smallest space which can hold the requested item. The DISPOSE actually does dispose the item passed to it. Garbage collection is done via the routine MAXAVAIL (or when necessary by NEW)which gathers all of the free memory into a free list, combines adjacent blocks, and reports the largest available block of memory. MEMAVAIL returns the largest never allocated memory space.
The second way in which to use the heap is to use the NEW, DISPOSE, and MEMAVAIL which are part of the PASLIB.ERL run-time library. In this implementation, the heap is treated as a stack. NEW puts the dynamic data on top of the stack which grows from the end of the user's static data towards the hardware stack. DISPOSE acutally does nothing. It is just there for symbol table use. The UCSD Pascal's MARK and RELEASE routines may be simulated using the system integer SYSMEM which points to the top of the heap:
MODULE UCSDHEAP; VAR SYSMEM : EXTERNAL INTEGER; PROCEDURE MARK(VAR P:INTEGER); BEGIN P := SYSMEM END; PROCEDURE RELEASE(P: INTEGER); BEGIN SYSMEM := P END; MODEND.