Next: , Previous: Accessing Command Line Arguments, Up: Library Routines

6.10.4 Memory Management 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;
       Vector = array [0 .. 1023] of Integer;
       VecPtr = ^Vector;
       p, q: VecPtr;
       GetMem (p, 1024 * SizeOf (Integer));
       q := VecPtr (@p^[512]);
       { ... }
       FreeMem (p, 512 * SizeOf (Integer));
       { ... }
       FreeMem (q, 512 * SizeOf (Integer));