uses
  dstrings,
  dchainedallocator;

var
  ChainedAllocator: TChainedAllocator;
  StaticMem: array[0 .. 127] of Byte;
  P: Pointer;

begin
  ChainedAllocator.Init(@StaticMem[0], Length(StaticMem));
  if not ChainedAllocator.TryAllocLeft(16, P) then
    Writeln(stderr, 'Error');
  Writeln(PtrUInt(P));
  if not ChainedAllocator.TryAllocLeft(16, P) then
    Writeln(stderr, 'Error');
  Writeln(PtrUInt(P));
  if not ChainedAllocator.TryAllocRight(16, P) then
    Writeln(stderr, 'Error');
  Writeln(PtrUInt(P));
  if not ChainedAllocator.TryAllocRight(16, P) then
    Writeln(stderr, 'Error');
  Writeln(PtrUInt(P));
  if ChainedAllocator.TryAllocRight(Length(StaticMem), P) then
    Writeln(stderr, 'Error');
  ChainedAllocator.AddHeapMemory(GetMem(1024), 1024);
  if not ChainedAllocator.TryAllocRight(Length(StaticMem), P) then
    Writeln(stderr, 'Error');
  Writeln(PtrUInt(P));
  ChainedAllocator.Done;
  Writeln('OK');
end.
