home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / packer / arc / arctool / tpstack.doc < prev    next >
Encoding:
Text File  |  1988-09-28  |  2.9 KB  |  91 lines

  1.                        F i l e    I n f o r m a t i o n
  2.  
  3. * DESCRIPTION
  4. Documentation file for TPSTACK.PAS.
  5.  
  6. * ASSOCIATED FILES
  7. TPSTACK.PAS
  8. TPSTACK.ASM
  9. TPSTACK.DOC
  10. TPSTACK.OBJ
  11. }
  12. TPSTACK - Unit for Monitoring Heap and Stack Usage
  13. -------------------------------------------------------
  14. Brian Foley
  15. TurboPower Software
  16. 6/88
  17. Version 1.00
  18. Released to the public domain
  19.  
  20. Overview
  21. ------------------------------------------------------------------------------
  22. TPSTACK allows you to accurately monitor a program's stack and heap usage
  23. simply by adding TPSTACK to the beginning of the program's USES list. The
  24. following program demonstrates how to use it:
  25.  
  26.   program TpStackTest;
  27.     {-Simple program to test TpStack}
  28.   uses
  29.     TpStack,
  30.     CRT;
  31.   var
  32.     P : Pointer;
  33.  
  34.     procedure StackEater;
  35.       {-Use some stack space}
  36.     var
  37.       BigArray : array[1..12331] of Byte; {this is on the stack}
  38.     begin
  39.       {delay a moment to insure that TpStack sees what we've used}
  40.       Delay(10);
  41.     end;
  42.  
  43.   begin
  44.     {use some stack and heap space}
  45.     GetMem(P, 56789);
  46.     StackEater;
  47.   end.
  48.  
  49. If you run this little demo program, you'll see that TpStack automatically
  50. displays the amount of heap and stack space used by the program when it ends.
  51.  
  52. Normally it is just this easy. In some cases, however, you may want or need to
  53. handle the reporting of results yourself. If so, you would set
  54. ReportStackUsage to False and call CalcStackUsage to obtain the necessary
  55. information.
  56.  
  57. If you want to disable stack monitoring temporarily--when executing other
  58. programs, for example--you can call RestoreInt8 to disable it and InstallInt8
  59. to reenable it.
  60.  
  61. TpStack can monitor only a single stack segment, normally the one in use when
  62. the program began. If you need to use it in a program that uses an alternate
  63. stack (a memory resident program, perhaps), you'll have to initialize three
  64. global variables before the first time that you switch to that stack. Here's
  65. an example:
  66.  
  67.    {disable TpStack momentarily}
  68.    RestoreInt8;
  69.    {OurSS has the stack segment to watch}
  70.    OurSS := AlternateStackSegment;
  71.    {InitialSP has the value of "SP" when the program began}
  72.    InitialSP := TopOfAlternateStack;
  73.    {LowestSP has the lowest value of SP so far, same as InitialSP at first}
  74.    LowestSP := InitialSP;
  75.    {reactivate TpStack}
  76.    InstallInt8;
  77.  
  78. Finally, in order to improve the accuracy of its results, TpStack reprograms
  79. the timer chip so that it can get control of the machine over 1000 times a
  80. second. For this reason, TpStack should not be used in programs that
  81. themselves reprogram the chip, or in programs that are using the PEP unit in
  82. Turbo Analyst. If you wish to change the rate at which samples are taken, you
  83. can call the SetSampleRate routine:
  84.  
  85.    {select 100 samples per second}
  86.    SetSampleRate(100);
  87.  
  88. The minimum value allowed is 18 samples per second, which is what the rate
  89. would be TpStack didn't reprogram the timer.
  90. 
  91.