[comp.sys.amiga.programmer] SAS C Stack Question

lordbah@amusing.uucp (Jeff Van Epps) (04/14/91)

I have a program which runs in the foreground, doing I/O to the console
it was started from.  How can I guarantee from within the code that the
program gets started with a stack >= some given size?  The manuals give
an example for linking with (cres.o or cback.o, forget which), but this
program runs in foreground and is currently not eligible for resident.

--------------------------------------------------------------------
    Jeff Van Epps    uunet!amusing!lordbah

ben@epmooch.UUCP (Rev. Ben A. Mesander) (04/15/91)

>In article <1991Apr15.234658.21860@uservx.afwl.af.mil> galetti@uservx.afwl.af.mil writes:
[...]
>I probably missed this in a previous discussion, so I apologize if it's a
>redundant question, but how do you know how much stack space a particular
>program needs in SAS C?  I just wrote a program that has six 100-element
>integer arrays and it bombed with 8000 bytes of stack space.  10,000 bytes
>seemed to be enough, but man I hate playing guessing games.  How much
>space does a program need, and how do you tell how much it needs?

Well, for starters 6 * 4 * 100 = 2400, but you need space for
everything else also.. I always declare large arrays static so that
they do not go on the stack. Usually there's no compelling reason to
make large arrays automatic. This really helps save stack space.


>-Ralph

--
| ben@epmooch.UUCP   (Ben Mesander)       | "Cash is more important than |
| ben%servalan.UUCP@uokmax.ecn.uoknor.edu |  your mother." - Al Shugart, |
| !chinet!uokmax!servalan!epmooch!ben     |  CEO, Seagate Technologies   |

jpotter@ucs.adelaide.edu.au (Jonathan Potter) (04/15/91)

In article <lordbah.3546@amusing.uucp> lordbah@amusing.uucp (Jeff Van Epps) writes:
>I have a program which runs in the foreground, doing I/O to the console
>it was started from.  How can I guarantee from within the code that the
>program gets started with a stack >= some given size?  The manuals give
>an example for linking with (cres.o or cback.o, forget which), but this
>program runs in foreground and is currently not eligible for resident.
>
>--------------------------------------------------------------------
>    Jeff Van Epps    uunet!amusing!lordbah

I know its not exactly what you want, but you could just CHECK to see that you
had enough stack, and if not, abort with an error message. To do this :

struct Process *myproc;

myproc=(struct Process *)FindTask(0);
if (myproc->pr_StackSize<desired_stack_size) abortgracefully();


Jon
-- 
| Jonathan Potter  |                             | Life is like a piece of   |
| P.O. Box 289     | jpotter@itd.adelaide.edu.au |   spinach...              |
| Goodwood, SA     | FidoNet : 3:680/829         |                           |
| Australia  5034  |                             | Sort of green and wrinkly |

galetti@uservx.afwl.af.mil (04/16/91)

In article <2858@sirius.ucs.adelaide.edu.au>, jpotter@ucs.adelaide.edu.au (Jonathan Potter) writes:
> In article <lordbah.3546@amusing.uucp> lordbah@amusing.uucp (Jeff Van Epps) writes:
>>I have a program which runs in the foreground, doing I/O to the console
>>it was started from.  How can I guarantee from within the code that the
>>program gets started with a stack >= some given size?  The manuals give
>>an example for linking with (cres.o or cback.o, forget which), but this
>>program runs in foreground and is currently not eligible for resident.
>>
>>--------------------------------------------------------------------
>>    Jeff Van Epps    uunet!amusing!lordbah
> 
> I know its not exactly what you want, but you could just CHECK to see that you
> had enough stack, and if not, abort with an error message. To do this :
> 
> struct Process *myproc;
> 
> myproc=(struct Process *)FindTask(0);
> if (myproc->pr_StackSize<desired_stack_size) abortgracefully();
> 
> 
> Jon
> -- 

I probably missed this in a previous discussion, so I apologize if it's a
redundant question, but how do you know how much stack space a particular
program needs in SAS C?  I just wrote a program that has six 100-element
integer arrays and it bombed with 8000 bytes of stack space.  10,000 bytes
seemed to be enough, but man I hate playing guessing games.  How much
space does a program need, and how do you tell how much it needs?

-Ralph

> | Jonathan Potter  |                             | Life is like a piece of   |
> | P.O. Box 289     | jpotter@itd.adelaide.edu.au |   spinach...              |
> | Goodwood, SA     | FidoNet : 3:680/829         |                           |
> | Australia  5034  |                             | Sort of green and wrinkly |
  ___________________________________________________________________________
 /   Ralph Galetti                  Internet:   galetti@uservx.afwl.af.mil   \
|    PL/LITT                        Interests:  computers, music, computers   |
|    Kirtland AFB, NM 87117-6008                and music, golf, sleep.       |
 \__"No, they couldn't actually prove that it was HIS vomit" - Nigel Tufnel__/

jbickers@templar.actrix.gen.nz (John Bickers) (04/18/91)

Quoted from <1991Apr15.234658.21860@uservx.afwl.af.mil> by galetti@uservx.afwl.af.mil:
> redundant question, but how do you know how much stack space a particular

    Estimate.

> program needs in SAS C?  I just wrote a program that has six 100-element
> integer arrays and it bombed with 8000 bytes of stack space.  10,000 bytes

    6 * 100 * 4, if you declared these things on the stack. As the
    programmer, you know how much stack space you use (though variables
    that will be allocated on the stack, and through function calls (esp.
    recursion)).

    I also read somewhere that on top of what you know you'll need, you
    also need to leave some space for system routines. Something like
    2.5K for AmigaDOS library functions.

> -Ralph
--
*** John Bickers, TAP, NZAmigaUG.        jbickers@templar.actrix.gen.nz ***
***         "Patterns multiplying, re-direct our view" - Devo.          ***