Bonjour Robespierre, comment ca va?
Wie wäre es mit folgendem Beispiel für einen universellen LiFo-Puffer...
Delphi-Quellcode:
type _Mem_Space = Array[0..maxInt-1]of Byte;
_L_List = ^_L_List_Node;
_L_List_Node = record
Size : Integer;
Info : ^_Mem_Space;
Next : _L_List end;
TLiFo = _L_List;
// ----------------------------------------------------- LiFo - LastIn/FirstOut
procedure InitLiFo(var L:TLiFo);
begin
L:=nil;
end;
procedure FreeLiFo(var L:TLiFo);
var p : TLiFo;
begin
while L<>nil do begin
p:=L;
with p^ do begin
FreeMem(Info,Size);
L:=Next;
end;
end;
end;
function IsEmpty(L:TLiFo):Boolean;
begin
Result:=L=nil
end;
function LiFoCount(L:TLiFo):Integer;
var p : TLiFo;
begin
Result:=0;
while L<>nil do begin
p:=L;
L:=p^.Next;
inc(Result);
end;
end;
procedure Push(var L:TLiFo;var Value;Len:Integer);
var p : TLiFo;
begin
new(p);
with p^ do begin
Size:=Len;
Next:=L;
GetMem(Info,Size);
Move(Value,Info^,Size);
end;
L:=p;
end;
procedure Pop(var L:TLiFo;var Value;Len:Integer);
var p : TLiFo;
begin
p:=L;
with p^ do begin
if Size<>Len then begin ShowMessage('Variablenlänge inkompatibel');
exit;
end;
Move(Info^,Value,Size);
FreeMem(Info,Size);
L:=Next;
end;
end;