home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / EEDRW23S.ZIP / STACK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-10  |  1.9 KB  |  58 lines

  1. /******************************************************************************
  2. * STACK - TC stack usage measuring routines.                      *
  3. *                                          *
  4. *                    Written by Gershon Elber,  Dec. 1990  *
  5. *******************************************************************************
  6. * History:                                      *
  7. *  10 Dec 90 - Version 1.0 by Gershon Elber.                      *
  8. ******************************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <dos.h>
  13.  
  14. /* #define DEBUG_TC_STACK */
  15.  
  16. #define TC_STACK_CHAR    'S'
  17.  
  18. /******************************************************************************
  19. * Clear all the stack space to a known pattern.                      *
  20. ******************************************************************************/
  21. void TCStackTestInit(void)
  22. {
  23.     unsigned int i = _SP - 10;                   /* To play it safe... */
  24.     char far *p = MK_FP(_SS, 0);
  25.  
  26.     while (i-- > 0) *p++ = TC_STACK_CHAR;      /* Preset all stack space. */
  27. }
  28.  
  29. /******************************************************************************
  30. * Scans the stack to decide what part of it has be overwritten by the stack   *
  31. * during run time. Returns this unused space size in bytes.              *
  32. ******************************************************************************/
  33. int TCStackTestSize(void)
  34. {
  35.     unsigned int i = 0;
  36.     char far *p = MK_FP(_SS, 0);
  37.  
  38.     while (*p++ == TC_STACK_CHAR) i++;
  39.  
  40.     return i;
  41. }
  42.  
  43. #ifdef DEBUG_TC_STACK
  44.  
  45. /******************************************************************************
  46. * Simple tests for the above routines.                          *
  47. ******************************************************************************/
  48. void main(void)
  49. {
  50.     TCStackTestInit();
  51.  
  52.     /* Do all your program here. */
  53.  
  54.     printf("%d bytes of stack are unused.\n", TCStackTestSize());
  55. }
  56.  
  57. #endif /* DEBUG_TC_STACK */
  58.