home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14899 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  2.8 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!ames!data.nas.nasa.gov!taligent!apple!grobbins
  2. From: grobbins@Apple.COM (Grobbins)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: How to increase stack size ???
  5. Message-ID: <71922@apple.Apple.COM>
  6. Date: 2 Sep 92 18:55:00 GMT
  7. References: <1992Sep1.145611.1@uwovax.uwo.ca> <1992Sep2.154822.12924@novell.com>
  8. Organization: Apple Computer Inc., Cupertino, CA
  9. Lines: 58
  10.  
  11. In article <1992Sep2.154822.12924@novell.com> damurphy@wc.novell.com (Duane A Murphy) writes:
  12. >In article <1992Sep1.145611.1@uwovax.uwo.ca> tschneid@uwovax.uwo.ca writes:
  13. >>...I keep running out of stack space.
  14. >
  15. >I also ran into a stack limitation problem.  Actually the stack is handled 
  16. >differently on different machines.  It is not consistent.  "Small" machines
  17. >have an 8K stack.  "Large" machines have a 24K stack.  There is a low memory
  18. >global "DefltStack" that determines the stack size at startup.  Dont mess 
  19. >with this, it affects everyone.
  20.  
  21. Color QuickDraw machines do have a 24K default stack.  Be aware that
  22. the Process Manager always increases the partition size by (default
  23. stack - 8K) when launching applications, so the extra 16K stack space
  24. on Color QuickDraw machines does not reduce the heap size under what
  25. would be available on a 68000 machine (but the app's partition is
  26. 16K larger than the partition size set by the programmer.)
  27.  
  28. >pascal Ptr StackPtr(void) = {0x2e8f};    /* MOVE A7, (A7) */
  29. >...
  30. >    SetApplLimit(StackPtr() - STACK_MIN);
  31.  
  32. This is a bit more 680x0 dependent than source code should be these
  33. days.  Here's a function which uses documented calls to increase the
  34. stack size.
  35.  
  36.   // Increase the space allocated for the application stack
  37.   //
  38.   // Warning: SetApplLimit always sets the stack to at least as large as the 
  39.   //    default stack for the machine (8K on machines with original QuickDraw,  
  40.   //    24K on machines with Color QuickDraw) so the application partition 
  41.   //    must be large enough to accomodate an appropriate stack and heap
  42.  
  43.   OSErr IncreaseApplicationStack(Size incrementSize)
  44.   {
  45.     OSErr retCode;
  46.   
  47.     // increase the stack size by lowering the heap limit
  48.     SetApplLimit((Ptr) ((unsigned long) GetApplLimit() - incrementSize));
  49.     retCode = MemError();
  50.     if (retCode == noErr) MaxApplZone();
  51.   
  52.     return retCode;
  53.   }
  54.  
  55. Do heed the warning given in the comment.  All stack allocation beyond
  56. the default must be compensated for by increasing the partition size in
  57. the SIZE -1 resource.  
  58.  
  59. This is particularly an issue for faceless background apps, which have
  60. a default stack size of only 2K.  SetApplLimit will grow an FBA's stack
  61. to at least 24K on Color QuickDraw machines, so the partition size
  62. should be larger than that.
  63.  
  64.  
  65. Grobbins               grobbins@apple.com
  66.  
  67. Usual disclaimers apply.
  68.  
  69.