home *** CD-ROM | disk | FTP | other *** search
- TPSTACK - Unit for Monitoring Heap and Stack Usage
- -------------------------------------------------------
- Brian Foley
- TurboPower Software
- 6/88
- Version 1.00
- Released to the public domain
-
- Overview
- ------------------------------------------------------------------------------
- TPSTACK allows you to accurately monitor a program's stack and heap usage
- simply by adding TPSTACK to the beginning of the program's USES list. The
- following program demonstrates how to use it:
-
- program TpStackTest;
- {-Simple program to test TpStack}
- uses
- TpStack,
- CRT;
- var
- P : Pointer;
-
- procedure StackEater;
- {-Use some stack space}
- var
- BigArray : array[1..12331] of Byte; {this is on the stack}
- begin
- {delay a moment to insure that TpStack sees what we've used}
- Delay(10);
- end;
-
- begin
- {use some stack and heap space}
- GetMem(P, 56789);
- StackEater;
- end.
-
- If you run this little demo program, you'll see that TpStack automatically
- displays the amount of heap and stack space used by the program when it ends.
-
- Normally it is just this easy. In some cases, however, you may want or need to
- handle the reporting of results yourself. If so, you would set
- ReportStackUsage to False and call CalcStackUsage to obtain the necessary
- information.
-
- If you want to disable stack monitoring temporarily--when executing other
- programs, for example--you can call RestoreInt8 to disable it and InstallInt8
- to reenable it.
-
- TpStack can monitor only a single stack segment, normally the one in use when
- the program began. If you need to use it in a program that uses an alternate
- stack (a memory resident program, perhaps), you'll have to initialize three
- global variables before the first time that you switch to that stack. Here's
- an example:
-
- {disable TpStack momentarily}
- RestoreInt8;
- {OurSS has the stack segment to watch}
- OurSS := AlternateStackSegment;
- {InitialSP has the value of "SP" when the program began}
- InitialSP := TopOfAlternateStack;
- {LowestSP has the lowest value of SP so far, same as InitialSP at first}
- LowestSP := InitialSP;
- {reactivate TpStack}
- InstallInt8;
-
- Finally, in order to improve the accuracy of its results, TpStack reprograms
- the timer chip so that it can get control of the machine over 1000 times a
- second. For this reason, TpStack should not be used in programs that
- themselves reprogram the chip, or in programs that are using the PEP unit in
- Turbo Analyst. If you wish to change the rate at which samples are taken, you
- can call the SetSampleRate routine:
-
- {select 100 samples per second}
- SetSampleRate(100);
-
- The minimum value allowed is 18 samples per second, which is what the rate
- would be TpStack didn't reprogram the timer.