home *** CD-ROM | disk | FTP | other *** search
- {TUG PDS CERT 1.01 (Pascal)
-
- ==========================================================================
-
- TUG PUBLIC DOMAIN SOFTWARE CERTIFICATION
-
- The Turbo User Group (TUG) is recognized by Borland International as the
- official support organization for Turbo languages. This file has been
- compiled and verified by the TUG library staff. We are reasonably certain
- that the information contained in this file is public domain material, but
- it is also subject to any restrictions applied by its author.
-
- This diskette contains PROGRAMS and/or DATA determined to be in the PUBLIC
- DOMAIN, provided as a service of TUG for the use of its members. The
- Turbo User Group will not be liable for any damages, including any lost
- profits, lost savings or other incidental or consequential damages arising
- out of the use of or inability to use the contents, even if TUG has been
- advised of the possibility of such damages, or for any claim by any
- other party.
-
- To the best of our knowledge, the routines in this file compile and function
- properly in accordance with the information described below.
-
- If you discover an error in this file, we would appreciate it if you would
- report it to us. To report bugs, or to request information on membership
- in TUG, please contact us at:
-
- Turbo User Group
- PO Box 1510
- Poulsbo, Washington USA 98370
-
- --------------------------------------------------------------------------
- F i l e I n f o r m a t i o n
-
- * DESCRIPTION
- Version 1.0. Author Richard S. Sadowsky. This unit, when used in a Turbo
- Pascal 4.0 program will automaticall report information about stack usage.
- This is very useful during program development. The following information
- is reported about the stack: total stack space, unused stack space and
- stack space used by your program.
-
- * ASSOCIATED FILES
- STACKUSE.PAS
- TESTSTAC.PAS
-
- * CHECKED BY
- DRM 08/08/88
-
- * KEYWORDS
- TURBO PASCAL V4.0
-
- ==========================================================================
- }
- {***********************************************************
- StackUse - A unit to report stack usage information
-
- by Richard S. Sadowsky
- version 1.0 7/18/88
- released to the public domain
-
- Inspired by a idea by Kim Kokkonen.
-
- This unit, when used in a Turbo Pascal 4.0 program, will
- automatically report information about stack usage. This
- is very useful during program development. The following
- information is reported about the stack:
-
- total stack space
- Unused stack space
- Stack spaced used by your program
-
- The unit's initialization code handles three things, it
- figures out the total stack space, it initializes the
- unused stack space to a known value, and it sets up an
- ExitProc to automatically report the stack usage at
- termination. The total stack space is calculated by
- adding 4 to the current stack pointer on entry into
- the unit. This works because on entry into a unit the
- only thing on the stack is the 2 word (4 bytes) far
- return value. This is obviously version and compiler
- specific.
-
- The ExitProc StackReport handles the math of calculating
- the used and unused amount of stack space, and displays
- this information. Note that the original ExitProc
- (Sav_ExitProc) is restored immediately on entry to
- StackReport. This is a good idea in ExitProc in case
- a runtime (or I/O) error occurs in your ExitProc!
-
- I hope you find this unit as useful as I have!
-
- ***********************************************************}
- {$R-,S-} { we don't need no stinkin range or stack checking! }
- unit StackUse;
-
- interface
-
- var
- Sav_ExitProc : Pointer; { to save the previous ExitProc }
- StartSPtr : Word; { holds the total stack size }
-
- implementation
-
- {$F+} { this is an ExitProc so it must be compiled as far }
- procedure StackReport;
-
- { This procedure may take a second or two to execute, especially }
- { if you have a large stack. The time is spent examining the }
- { stack looking for our init value ($AA). }
-
- var
- I : Word;
-
- begin
- ExitProc := Sav_ExitProc; { restore original exitProc first }
-
- I := 0;
- { step through stack from bottom looking for $AA, stop when found }
- while I < SPtr do
- if Mem[SSeg:I] <> $AA then begin
- { found $AA so report the stack usage info }
- WriteLn('total stack space : ',StartSPtr);
- WriteLn('unused stack space: ', I);
- WriteLn('stack space used : ',StartSPtr - I);
- I := SPtr; { end the loop }
- end
- else
- inc(I); { look in next byte }
- end;
- {$F-}
-
-
- begin
- StartSPtr := SPtr + 4; { on entry into a unit, only the FAR return }
- { address has been pushed on the stack. }
- { therefore adding 4 to SP gives us the }
- { total stack size. }
- FillChar(Mem[SSeg:0], SPtr - 20, $AA); { init the stack }
- Sav_ExitProc := ExitProc; { save exitproc }
- ExitProc := @StackReport; { set our exitproc }
- end.