home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST1001.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  2.3 KB  |  51 lines

  1. {$M $4000,0,$8000}
  2. Program HeapMemoryUsage;
  3. {-------------------------------------------------------------------------}
  4. { This program is a demonstration of how quickly repetitive calls to      }
  5. { InitGraph will eat up heap memory, leaving very little memory available }
  6. { for other dynamic operations.                                           }
  7. {-------------------------------------------------------------------------}
  8.  
  9. Uses Graph, Crt;  { Links in the necessary library units for this demo.   }
  10.  
  11. Const
  12.   PathForDrivers = '';          { Location of the BGI and CHR files.      }
  13.   ExitLoop : Boolean = False;   { Exiting condition for repeat loop.      }
  14.  
  15. Var
  16.   GraphDriver,                  { Graph Driver to be passed to InitGraph  }
  17.   GraphMode : Integer;          { Graph Mode to be passed to InitGraph    }
  18.   Count : Word;                 { Number of successful calls to InitGraph }
  19.   GrErr : Integer;              { Error result from call to InitGraph     }
  20.  
  21. Begin
  22.   GraphDriver := Detect;        { Instruct Graph unit to Auto Detect      }
  23.   Count := 0;                   { Initialize counter to 0                 }
  24.   Repeat
  25.     InitGraph( GraphDriver,GraphMode,PathFordrivers );
  26.                                 { Place computer into Graphics Mode       }
  27.     GrErr := GraphResult;       { Store result of InitGraph call          }
  28.     If( GrErr <> 0 ) Then
  29.     Begin
  30.       If( GrErr = -5 ) Then     { -5 Indicates not enough heap memory     }
  31.       Begin
  32.         RestoreCrtMode;         { Make sure we are in a Text Mode         }
  33.         Write( 'There is no longer sufficient memory on the Heap.  ' );
  34.         Writeln( 'InitGraph was called ', Count, ' times,' );
  35.         Write( 'and there is now only ', MemAvail, ' bytes ' );
  36.         Writeln( 'left in Heap Memory.' );
  37.         ExitLoop := True;       { Set condition to exit loop              }
  38.       End
  39.       Else
  40.         Writeln( GraphErrorMsg( GrErr ) );
  41.                                 { Guard against some other error condition}
  42.     End
  43.     Else
  44.     Begin
  45.       RestoreCrtMode;           { Flip from Graphics to Text Mode         }
  46.       Inc( Count );             { Incriment the loop counter variable     }
  47.     End;
  48.   Until ExitLoop;
  49.   Readln;                       { Pause for output screen viewing.        }
  50. End.
  51.