[comp.lang.pascal] Stack size in turbo pas

MATHRICH@umcvmb.missouri.edu (Rich Winkel UMC Math Department) (05/15/89)

It's difficult to tell how much is needed, because you don't know what's
going on in the pascal runtime library and during program initialization etc.

Aside from the pascal-related stack allocation, you have to worry about
stack usage by (possibly nested) hardware interrupt routines, such as
the timer tick and keyboard.  The ROM keyboard interrupt pushes around 10
words (20 bytes).  If you have TSR routines hooked to the keyboard or timer,
especially if they make DOS calls, you could be using 100 bytes very easily.

A rule of thumb I seem to remember from my asm days is to add 256 bytes
to whatever stack usage your program is responsible for.  While this might
seem excessive, the price of stack overflow is pretty high.

Rich

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (05/17/89)

In article <19601@adm.BRL.MIL> MATHRICH@umcvmb.missouri.edu (Rich Winkel UMC Math Department) writes:
>A rule of thumb I seem to remember from my asm days is to add 256 bytes
>to whatever stack usage your program is responsible for.  While this might
>seem excessive, the price of stack overflow is pretty high.

I think it's fairly unsafe in a Turbo Pascal program that does any I/O to
have less than 1K more than you can see you're using.  Most of the string
manipulation routines (e.g. "+") allocate a full sized string (256 bytes)
on the stack whether they need it or not;  I'm not sure if my 1K figure makes 
allowances for this.  A simple way to find out is to turn on stack checking, 
and just keep reducing the stack until you get overflows.  Then add as much 
insurance space as you can afford.

Duncan Murdoch