home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / interpre / p_pascal / samples / newtest.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-10-18  |  2.7 KB  |  74 lines

  1. (*$c+*)
  2. PROGRAM Listtest;
  3. TYPE    Ptr_1 = ^Node_1;
  4.     Ptr_2 = ^Node_2;
  5.     Ptr_3 = ^Node_3;
  6.     Node_1 = RECORD
  7.           part1 : ARRAY [1:199] OF Integer;
  8.           next : ^Node_1
  9.          END;
  10.     Node_2 = RECORD
  11.           part2 : ARRAY [1:34] OF Integer;
  12.           next : ^Node_2
  13.          END;
  14.     Node_3 = RECORD
  15.          part3 : ARRAY [1:149] OF Integer;
  16.          next : ^Node_3
  17.         END;
  18. VAR    Holder_1 : Ptr_1;
  19.     Holder_2 : Ptr_2;
  20.     Holder_3 : Ptr_3;
  21.     i : Integer;
  22.     Marker : ^Integer;
  23. BEGIN
  24.  { NOTE: UPPERCASE IS NOT NECESSARY; I JUST LIKE TO USE IT. }
  25.  { --------------------------------------------------------- }
  26.  { In this system, NEW() allocates individual Pascal data }
  27.  { nodes, and DISPOSE() releases these nodes.  Most Pascal }
  28.  { programs work quite well with a liberal use of NEW() and }
  29.  { an occasional use of DISPOSE(). For programs that consume }
  30.  { and discard large numbers of nodes, MARK(^Integer ) and }
  31.  { RELEASE(^Integer) provide a mechanism for preventing  }
  32.  { depletion of the Pascal heap. MARK() saves the heap state }
  33.  { as an Integer pointer BEFORE allocation using NEW() }
  34.  { begins, and RELEASE() restores the heap to that state }
  35.  { AFTER the memory allocated by NEW() is no longer needed. }
  36.  { Note that MARK() and RELEASE() do not have to appear in }
  37.  { the same procedure. All that is needed is for them to have }
  38.  { the same Integer pointer parameter. }
  39.  { ---------------------------------------------------------- }
  40.  { Save the heap address in Marker: }
  41.  MARK(Marker);
  42.  FOR i := 1 TO 5 DO
  43.   BEGIN
  44.    NEW(Holder_1);
  45.    { Breaking strings up is not necessary, just illustrated }
  46.    { here as a way of demonstrating the use of common string }
  47.    { suffixes to minimize space used by string constants in }
  48.    { the run-time system.  The common string suffixes are }
  49.    { stored by the system only once for each string: }
  50.    WRITELN('Allocation of 200',' words, iteration ',i:1,' .');
  51.    { DISPOSE() is used here to return the nodes acquired from }
  52.    { the Pascal heap to the Pascal List of Available Space }
  53.    { (LAVS). This tests the operation of the Pascal heap }
  54.    { administrator, and can be used on other Pascal systems }
  55.    { as a similar test. }
  56.    IF i <= 3 THEN DISPOSE(Holder_1)
  57.   END;
  58.  { Return all the NEW() nodes to the heap in one operation: }
  59.  RELEASE(Marker);
  60.  i := 1;
  61.  { Allocate and relaease nodes until a failure occurs. Nodes }
  62.  { will be drawn from both the Pascal heap and the List of }
  63.  { Available Space (LAVS): }
  64.  REPEAT
  65.   NEW(Holder_3);
  66.   WRITELN('Allocation of 150',' words, iteration ',i:1,' .');
  67.   NEW(Holder_2);
  68.   WRITELN('Allocation of 35', ' words, iteration ',i:1,' .');
  69.   DISPOSE(Holder_3);
  70.   { SUCC(i) is the most efficient way to increment i: }
  71.   i := SUCC(i)
  72.  UNTIL False
  73. END.
  74.