March 2000
Intermediate to advanced
576 pages
18h 13m
English
SysGetMem Function
function SysGetMem(Size: Integer): Pointer;
SysGetMem allocates Size bytes
of memory using Delphi’s built-in memory manager. It returns a
pointer to the newly allocated memory or nil for
an error. The memory is not
initialized.
SysGetMem is a real function.
If you write your own memory manager, you can call
SysGetMem to perform the memory allocation.
If you are not implementing a new memory manager, use
New or GetMem, not
SysGetMem, to allocate memory.
// See SetMemoryManager for an explanation of this memory manager.
// Allocate Size bytes and return a pointer to the new memory.
// Return nil for errors, and Delphi will raise an exception.
// Allocate extra bytes for debugging.
function DebugGet(Size: Integer): Pointer;
var
PArray: PIntegerArray;
begin
Size := RoundUpSize(Size);
// Allocate enough room for 2 guard words: at the start and end
// of the block.
PArray := SysGetMem(Size + 2*GuardSize);
if PArray = nil then
Result := nil
else
begin
// Store the guard words.
PArray[0] := AllocatedGuard;
PArray[Size div GuardSize + 1] := AllocatedGuard;
// Return a pointer to the memory just past the first guard.
Result := @PArray[1];
end;
end;| GetMem Procedure, GetMemory Function, GetMemoryManager Procedure, IsMemoryManagerSet Function, IsMultiThread Variable, New Procedure, SetMemoryManager Procedure, SysFreeMem Function, SysReallocMem Function, TMemoryManager Type |
Read now
Unlock full access