Name
SysFreeMem Function
Syntax
function SysFreeMem(P: Pointer): Integer;
Description
SysFreeMem
uses Delphi’s built-in memory
manager to free the memory that P
points to. It
returns zero for success and a non-zero error code if
P
is invalid or
nil
.
SysFreeMem
is a real function.
Tips and Tricks
SysFreeMem
is useful if you are writing your own memory manager as a filter and want to call Delphi’s memory manager from your custom memory manager.If you are not implementing a memory manager, use
Dispose
orFreeMem
, notSysFreeMem
, to free memory.FreeMem
andDispose
already check for anil
pointer, soSysFreeMem
doesn’t have to.
Example
// See SetMemoryManager for an explanation of this memory manager. // Return True if the memory pointed to by PArray is a valid heap block // and the guard words are intact. Return false for any error. function GuardsAreOkay(PArray: PIntegerArray; Fill: Boolean): Boolean; const DelphiInUseFlag = 2; MemMgrFlags = 7; var Size: LongWord; begin // First get the block size. The size is the long word before // the start of the block. Delphi sets the size and stores flags // in the 3 LSBits. Delphi's format is subject to change in future // releases. The middle bit is set for an allocated block. PArray := PIntegerArray(PChar(PArray) - SizeOf(Size)); Size := PArray[0]; PArray := PIntegerArray(PChar(PArray) + SizeOf(Size)); if (Size and DelphiInUseFlag) <> DelphiInUseFlag then begin Result := False; Exit; end; // Remove Delphi's flag from the size, and subtract the ...
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.