home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!ames!data.nas.nasa.gov!taligent!apple!grobbins
- From: grobbins@Apple.COM (Grobbins)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: How to increase stack size ???
- Message-ID: <71922@apple.Apple.COM>
- Date: 2 Sep 92 18:55:00 GMT
- References: <1992Sep1.145611.1@uwovax.uwo.ca> <1992Sep2.154822.12924@novell.com>
- Organization: Apple Computer Inc., Cupertino, CA
- Lines: 58
-
- In article <1992Sep2.154822.12924@novell.com> damurphy@wc.novell.com (Duane A Murphy) writes:
- >In article <1992Sep1.145611.1@uwovax.uwo.ca> tschneid@uwovax.uwo.ca writes:
- >>...I keep running out of stack space.
- >
- >I also ran into a stack limitation problem. Actually the stack is handled
- >differently on different machines. It is not consistent. "Small" machines
- >have an 8K stack. "Large" machines have a 24K stack. There is a low memory
- >global "DefltStack" that determines the stack size at startup. Dont mess
- >with this, it affects everyone.
-
- Color QuickDraw machines do have a 24K default stack. Be aware that
- the Process Manager always increases the partition size by (default
- stack - 8K) when launching applications, so the extra 16K stack space
- on Color QuickDraw machines does not reduce the heap size under what
- would be available on a 68000 machine (but the app's partition is
- 16K larger than the partition size set by the programmer.)
-
- >pascal Ptr StackPtr(void) = {0x2e8f}; /* MOVE A7, (A7) */
- >...
- > SetApplLimit(StackPtr() - STACK_MIN);
-
- This is a bit more 680x0 dependent than source code should be these
- days. Here's a function which uses documented calls to increase the
- stack size.
-
- // Increase the space allocated for the application stack
- //
- // Warning: SetApplLimit always sets the stack to at least as large as the
- // default stack for the machine (8K on machines with original QuickDraw,
- // 24K on machines with Color QuickDraw) so the application partition
- // must be large enough to accomodate an appropriate stack and heap
-
- OSErr IncreaseApplicationStack(Size incrementSize)
- {
- OSErr retCode;
-
- // increase the stack size by lowering the heap limit
- SetApplLimit((Ptr) ((unsigned long) GetApplLimit() - incrementSize));
- retCode = MemError();
- if (retCode == noErr) MaxApplZone();
-
- return retCode;
- }
-
- Do heed the warning given in the comment. All stack allocation beyond
- the default must be compensated for by increasing the partition size in
- the SIZE -1 resource.
-
- This is particularly an issue for faceless background apps, which have
- a default stack size of only 2K. SetApplLimit will grow an FBA's stack
- to at least 24K on Color QuickDraw machines, so the partition size
- should be larger than that.
-
-
- Grobbins grobbins@apple.com
-
- Usual disclaimers apply.
-
-