Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!ucbcad!ucbvax!hplabs!well!ewhac From: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Newsgroups: comp.sys.amiga Subject: Re: Dynamic Stack Allocation Message-ID: <4314@well.UUCP> Date: Tue, 27-Oct-87 05:08:30 EST Article-I.D.: well.4314 Posted: Tue Oct 27 05:08:30 1987 Date-Received: Thu, 29-Oct-87 21:43:31 EST References: <4585@zen.berkeley.edu> <21440@ucbvax.BERKELEY.EDU> Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Organization: Whole Earth 'Lectronic Link (how 'bout dat!) Lines: 37 In article <21440@ucbvax.BERKELEY.EDU> bryce@hoser.berkeley.edu (Bryce Nesbitt) writes: >In article <4585@zen.berkeley.edu> c164-1bj@cordelia.berkeley.edu (Jonathan Dubman) writes: >>Is it possible in a C program to know how much stack space I have? I >>can write a short assembly language program if necessary. > >From C, simply get a pointer to your task with "FindTask(0L);" This returns >a pointer to struct Task from the exec/tasks.h include file. tc_SPLower is >the lower bound of the stack tc_SPupper is the upper bound +2. > Gee Byrce, I'm surprised you missed this. Yes, there are tc_SP{Upper,Lower} fields in the task control block, but these are not what DOS uses for the stack. That's stored in your process structure (an extension of Exec's task structure). To find out the size of the stack DOS allocated for you when your program was started, you say: stacksize = ((struct Process *) FindTask (0L)) -> pr_StackSize; I found this out a while ago when trying to debug a program. For some strange reason I decided to check to see if the stack had a sane value. Much to my consternation, I found the stack pointer pointing completely outside the range specified by tc_SP{Upper,Lower}. It suddenly dawned on me that DOS was probably screwing this up, too, and poked around in the process structure. Hope this helps. (Hope I'm right about it, too!) _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape ihnp4!ptsfa -\ \_ -_ Recumbent Bikes: dual ---> !{well,unicom}!ewhac O----^o The Only Way To Fly. hplabs / (pronounced "AE-wack") "Although there are technical differences between the quality of images created on the Amiga and on our system, we feel that viewers could be misled to believe otherwise, even with your disclaimers to the contrary." -- Ralph J. Guggenheim, Pixar