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

## 9.104 GetMem

### Synopsis

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

or

    function GetMem (Size: Cardinal): Pointer;

### Description

Allocates dynamical storage on the heap and returns a pointer to it in ``p'` or as the function result.

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. The use of ``GetMem'` as a function is a GNU 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 }
      Buffer := GetMem (Size);  { or: GetMem (Buffer, Size); }
      { Do something with Buffer }
      FreeMem (Buffer)  { or: FreeMem (Buffer, Size) }
    end.

### See also

section 9.100 FreeMem, section 9.170 New, section 8.2.10.6 EP's Schema Types including ``String'`.

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