{$MODE OBJFPC}
{$MODESWITCH AUTODEREF}
uses
  dstrings,
  dpool;

type
TStaticInfo = object
public const
  PAGE_SIZE = 128;
  STATIC_SIZE = 16;
end;

PObject = ^TObject;
TObject = object
  S: AnsiString;
  Next: PObject;
  constructor Init;
  destructor Done; virtual;
end;
TPoolOfObject = specialize TPool<TObject, TStaticInfo>;

constructor TObject.Init;
begin
end;

destructor TObject.Done;
begin
  S := '';
end;

procedure DoneObject(O: PObject);
begin
  O^.Done;
end;

var
  Pool: TPoolOfObject;
  A, B, C: PObject;
  Statistics: TPoolOfObject.TStatistics;

begin
  Pool.Init;
  if Pool.Alloc(A) then
    A.Init;
  A.S := 'A';
  if Pool.Alloc(B) then
    B.Init;
  B.S := 'B';
  if Pool.Alloc(C) then
    C.Init;
  C.S := A.S + B.S;
  Pool.Dealloc(B);
  Pool.Dealloc(C);
  if Pool.Alloc(B) then
    B.Init;
  B.S := C.S + '?';
  Pool.ComputeStatistics(@Statistics);
  Writeln('pool size: ', Statistics.Size);
  Writeln('number of pages: ', Statistics.Pages);
  Writeln('values in pool: ', Statistics.Count);
  Writeln('allocated values: ', Statistics.AllocedCount);
  Writeln('semi-initialized values: ', Statistics.SemiInitialized);
  Writeln('non-initialized values: ', Statistics.NotInitialized);
  Pool.Dealloc(A);
  Pool.Dealloc(B);
  Pool.DoForEachSemiInitialized(@DoneObject);
  Pool.Done;
end.
