[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.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);

GPC also supports function style call to GetMem:

 
MyPtr := GetMem (1024);

(see also: New in context of Object Orientated Programming)

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.



This document was generated by Frank Heckenbach on May, 10 2002 using texi2html