home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / LEXMPSRC.RAR / HEAP.PAS < prev    next >
Pascal/Delphi Source File  |  2000-08-15  |  1KB  |  56 lines

  1. {█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
  2. {█                                                       █}
  3. {█      Virtual Pascal for Linux                         █}
  4. {█      Test example for heap functions                  █}
  5. {█      ─────────────────────────────────────────────────█}
  6. {█      Copyright (C) 1999 Joerg Pleumann                █}
  7. {█                                                       █}
  8. {▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
  9.  
  10. program Heap;
  11.  
  12. uses
  13.   VpSysLow;
  14.  
  15. const Max = 4096;
  16.  
  17. var
  18.   P: array[1..Max] of Pointer;
  19.   X, I: LongInt;
  20.  
  21. begin
  22.   WriteLn('Heap usage is ', AllocMemSize, ' bytes, free memory is ', MemAvail, ' bytes.');
  23.   WriteLn;
  24.  
  25.   WriteLn('Allocating ', Max, ' blocks of memory (press <Enter>).');
  26.   ReadLn;
  27.  
  28.   for I := 1 to Max do
  29.   begin
  30.     X := 1 + Random(16384);
  31.     GetMem(P[I], X);
  32.     FillChar(P[I]^, X, $FF);
  33.     Write('.');
  34.   end;
  35.   WriteLn;
  36.   WriteLn('Heap usage is ', AllocMemSize, ' bytes, free memory is ', MemAvail, ' bytes.');
  37.   WriteLn;
  38.  
  39.   WriteLn('De-allocating ', Max, ' blocks of memory (press <Enter>).');
  40.   ReadLn;
  41.  
  42.   for I := 1 to Max do
  43.   begin
  44.     FreeMem(P[I]);
  45.     Write('.');
  46.   end;
  47.  
  48.   WriteLn;
  49.   WriteLn('Heap usage is ', AllocMemSize, ' bytes, free memory is ', MemAvail, ' bytes.');
  50.   WriteLn;
  51.  
  52.   WriteLn('Terminating (press <Enter>).');
  53.   ReadLn;
  54. end.
  55.  
  56.