Code: Alles auswählen
procedure Free( var P );
var
head : PBlock_Header;
i : Integer;
size : Longint;
begin
if Pointer(P) = nil then exit; // Diese Zeile kapier ich nicht
i := -1;
head := @(PBlock_Headers(P)^[i]);
(* A hack to get the header in PB, as the line *)
(* @(PBlock_Headers(P)^[-1] would give a 'constant error' *)
(* at compile time. I'm unsure this works correctly in BP *)
if head^.magic <> Mark_Magic then
begin
(* PANIC : An invalid Free call *)
Writeln('Invalid Free call');
halt(1);
end;
size := head^.size;
head^.magic := 0; (* cleans the header *)
head^.size := 0;
FreeMem( head, size );
Pointer(P) := nil;
end;
Normalerweise gebe ich doch Speicer frei auf den eine Zeigervariable gerichtet ist. Warum ist das hier anders?