Dec 122017
Excellent program by the fellows at Turbo Power. Tracks your stack and heap usage as your program runs. Makes final memory setting easy.
File TPSTACK.ZIP from The Programmer’s Corner in
Category Pascal Source Code
Excellent program by the fellows at Turbo Power. Tracks your stack and heap usage as your program runs. Makes final memory setting easy.
File Name File Size Zip Size Zip Type
TPSTACK.ASM 3139 976 deflated
TPSTACK.DOC 2819 1268 deflated
TPSTACK.OBJ 351 296 deflated
TPSTACK.PAS 7183 2173 deflated
TPSTACK.TPU 1872 997 deflated

Download File TPSTACK.ZIP Here

Contents of the TPSTACK.DOC file

TPSTACK - Unit for Monitoring Heap and Stack Usage
Brian Foley
TurboPower Software
Version 1.00
Released to the public domain

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}
P : Pointer;

procedure StackEater;
{-Use some stack space}
BigArray : array[1..12331] of Byte; {this is on the stack}
{delay a moment to insure that TpStack sees what we've used}

{use some stack and heap space}
GetMem(P, 56789);

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

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}
{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}

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}

The minimum value allowed is 18 samples per second, which is what the rate
would be TpStack didn't reprogram the timer.

 December 12, 2017  Add comments

Leave a Reply