home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / chap15 / simpary / simpary.dpr next >
Encoding:
Text File  |  1995-03-21  |  1.0 KB  |  47 lines

  1. program SimpAry;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: SIMPARY }
  5.  
  6. { This program demonstrates how to create a pointer
  7.   to an array so that you can move it onto the heap
  8.   and out of the data segment. If you put large arrays
  9.   in the data segment, you will soon run out of memory;
  10.   that is, you will overflow the bounds of the data segment.
  11.   There is less than 64K available in the data segment
  12.   of a Windows program, and you cannot afford to
  13.   fill that space up with a few big arrays. As a result,
  14.   you should move most arrays up on the heap, by creating
  15.   pointers to arrays, as shown in this program. }
  16.  
  17. {$ifDef Windows}
  18. uses
  19.   WinCrt;
  20. {$EndIf}
  21.  
  22. const
  23.   Max = 65000;
  24.  
  25. type
  26.   PBigArray = ^TBigArray;
  27.   TBigArray = Array[0..Max] of Char;
  28.  
  29. var
  30.   BigArray: PBigArray;
  31.   i: Word;
  32.  
  33. begin
  34.   New(BigArray);
  35.  
  36.   for i := 0 To Max do
  37.     BigArray^[i] := 'a';
  38.  
  39.   for i := Max DownTo Max - 10 do
  40.     WriteLn(i, ' => ', BigArray^[i]);
  41.  
  42.   Dispose(BigArray);
  43. end.
  44.  
  45.  
  46.  
  47.