Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!uwvax!uwmacc!uwmcsd1!ig!jade!ucbvax!hoser.berkeley.edu!bryce From: bryce@hoser.berkeley.edu (Bryce Nesbitt) Newsgroups: comp.sys.amiga Subject: Re: Dynamic Stack Allocation Message-ID: <21440@ucbvax.BERKELEY.EDU> Date: Sun, 25-Oct-87 20:18:43 EST Article-I.D.: ucbvax.21440 Posted: Sun Oct 25 20:18:43 1987 Date-Received: Tue, 27-Oct-87 06:04:44 EST References: <4585@zen.berkeley.edu> Sender: usenet@ucbvax.BERKELEY.EDU Organization: University of California at Berkeley Lines: 33 Summary: Here is how to check how large your stack is. In article <4585@zen.berkeley.edu> c164-1bj@cordelia.berkeley.edu (Jonathan Dubman) writes: >I have a speedy maze program I wrote in C that I want to send to Fred and post >here, but it needs a large stack. Maximum resolution requires about 150K of >stack space. (Massive recursion.) I don't want everybody who runs it without >reading the docs first to crash their machine. > >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. It would be thoretically possible to allocate a new stack and start to use it. This sounds somewhat dangerous, however. There is no official function set up to swap stacks (and the requisite Task structure fields). In the future, particuarly the resource tracked future, you could be asking for problems. At least you know it is safe to: >say, "Reset your stack size and run me again.". Anyone starting it from Workbench will only get that message if they played with the icon. Anyone starting from the CLI when an icon exists can probably figure out how to type "stack 150000". Sounds like your program should also leave the automatic stack checking code in. This will pop a "Stack overflow" requester if a function call will overflow. You *must*, however, catch the exit and do a proper cleanup. |\ /| . Ack! (NAK, SOH, EOT) {o O} . bryce@hoser.berkeley.EDU -or- ucbvax!hoser!bryce (") U "Here. This'll shoot the lips off a cockroch" -Freedom Fighter