| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
procedure GetMem (var p: Pointeger; Size: Cardinal); |
function GetMem (Size: Cardinal): Pointer; |
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.
`GetMem' is a Borland Pascal extension. The use of `GetMem' as a function is a GNU Pascal extension.
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.
|
section 9.100 FreeMem, section 9.170 New, section 8.2.10.6 EP's Schema Types including `String'.