Next: , Previous: Get, Up: Reference



GetMem

Synopsis

     procedure GetMem (var p: Pointeger; Size: Cardinal);

Description

Allocates dynamical storage on the heap and returns a pointer to it in p.

Since Extended Pascal's schemata provide a cleaner way to implement dynamical arrays and such, we recommend using GetMem and FreeMem only for low-level applications.

Conforming to

GetMem is a Borland Pascal extension.

Example

The Borland-comatibility unit Graph from the BPcompat package supports a GetImage and a PutImage procedure which need a variable of size ImageSize as a buffer. Since these are “black box” routines, the buffer can't reasonably be a schema providing a dynamical array. Instead, we have to use GetMem and FreeMem for dynamical memory allocation.

     program GetMemDemo;
     var
       Buffer: Pointer;
       Size: Cardinal;
     begin
       Size := Random (10000);  { the size can be determined at run time }
       GetMem (Buffer, Size);
       { Do something with Buffer }
       FreeMem (Buffer)  { or: FreeMem (Buffer, Size) }
     end.

See also

FreeMem, New, Schema Types.