heapex.pp 533 B

1234567891011121314151617181920212223242526
  1. Program heapex;
  2. { Program used to demonstrate the usage of heaptrc unit }
  3. Uses heaptrc;
  4. Var P1 : ^Longint;
  5. P2 : Pointer;
  6. I : longint;
  7. begin
  8. New(P1);
  9. // causes previous allocation not to be de-allocated
  10. New(P1);
  11. Dispose(P1);
  12. For I:=1 to 10 do
  13. begin
  14. GetMem (P2,128);
  15. // When I is even, deallocate block. We loose 5 times 128
  16. // bytes this way.
  17. If (I mod 2) = 0 Then FreeMem(P2,128);
  18. end;
  19. GetMem(P2,128);
  20. // This will provoke an error and a memory dump
  21. Freemem (P2,64);
  22. end.