home *** CD-ROM | disk | FTP | other *** search
- {$M $4000,0,$8000}
- Program HeapMemoryUsage;
- {-------------------------------------------------------------------------}
- { This program is a demonstration of how quickly repetitive calls to }
- { InitGraph will eat up heap memory, leaving very little memory available }
- { for other dynamic operations. }
- {-------------------------------------------------------------------------}
-
- Uses Graph, Crt; { Links in the necessary library units for this demo. }
-
- Const
- PathForDrivers = ''; { Location of the BGI and CHR files. }
- ExitLoop : Boolean = False; { Exiting condition for repeat loop. }
-
- Var
- GraphDriver, { Graph Driver to be passed to InitGraph }
- GraphMode : Integer; { Graph Mode to be passed to InitGraph }
- Count : Word; { Number of successful calls to InitGraph }
- GrErr : Integer; { Error result from call to InitGraph }
-
- Begin
- GraphDriver := Detect; { Instruct Graph unit to Auto Detect }
- Count := 0; { Initialize counter to 0 }
- Repeat
- InitGraph( GraphDriver,GraphMode,PathFordrivers );
- { Place computer into Graphics Mode }
- GrErr := GraphResult; { Store result of InitGraph call }
- If( GrErr <> 0 ) Then
- Begin
- If( GrErr = -5 ) Then { -5 Indicates not enough heap memory }
- Begin
- RestoreCrtMode; { Make sure we are in a Text Mode }
- Write( 'There is no longer sufficient memory on the Heap. ' );
- Writeln( 'InitGraph was called ', Count, ' times,' );
- Write( 'and there is now only ', MemAvail, ' bytes ' );
- Writeln( 'left in Heap Memory.' );
- ExitLoop := True; { Set condition to exit loop }
- End
- Else
- Writeln( GraphErrorMsg( GrErr ) );
- { Guard against some other error condition}
- End
- Else
- Begin
- RestoreCrtMode; { Flip from Graphics to Text Mode }
- Inc( Count ); { Incriment the loop counter variable }
- End;
- Until ExitLoop;
- Readln; { Pause for output screen viewing. }
- End.