March 2000
Intermediate to advanced
576 pages
18h 13m
English
SysFreeMem Function
function SysFreeMem(P: Pointer): Integer;
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.
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 or FreeMem, not
SysFreeMem, to free memory.
FreeMem and Dispose already
check for a nil pointer, so
SysFreeMem doesn’t have to.
// 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 ...
Read now
Unlock full access