[comp.sys.mac.programmer] SetApplLimit

dan@lclark.UUCP (Dan Revel) (01/04/91)

I'm using SetApplLimit to set the stack size in my program as follows:

#define STACKSIZE	8192L

Ptr
GetSP()
{
	register Ptr	localSP;

	asm {
		movea.l sp,localSP
	};
	return(localSP);
}

InitMemory()
{
	Ptr	localSP;

	localSP = GetSP();
	SetApplLimit(localSP - STACKSIZE);
	MaxApplZone();

	/* ... etc. ... */
}

I'm pretty sure that this is the 'right' way to do it (I saw it on
comp.sys.mac.programmer :-)), but my application still gets a
system error 28 every now and then.
(system error 28 = dsStknHeap stack has moved into application heap)
So my question is: aside from trial and error how can I judge how large
a stack my application will need?  My guess was that 8K was more than
for any possible case... wrong!  So tell me does the operating system
or the toolbox or Think C 4.0 have an appetite for stack space I don't
know about or what?!

Thanks in advance,

Dan
-- 
dan@lclark.bitnet					SM 0 A9F4
tektronix!reed!lclark!dan				G 0

Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (01/07/91)

Dan Revel writes in a message to All

DR>  My guess was that 8K was more than for any possible case... 
DR> wrong! So tell me does the operating system or the toolbox or 
DR> Think C 4.0 have an appetite for stack space I don't know about 
DR> or what?!

Anytime you use DrawText, you put the entire text on the stack. Anytime you
use a Region, the ToolBox might use double the region size, etc.

8K was designed for the thin Mac, with only 128K of memory available. You 
might
want to change the heap size. IM vol 2, page 74, and IM vol 4, page 78 have
more details for things you can do...


Lawson
 

 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English
Internet: Lawson.English@p88.f15.n300.z1.fidonet.org

hairston@henry.ece.cmu.edu (David Hairston) (01/09/91)

[dan@lclark.UUCP (Dan Revel) writes:]
[] I'm using SetApplLimit to set the stack size in my program as follows:
[]
[] #define STACKSIZE	8192L
[]
[] Ptr
[] GetSP()
[] {
[]	   register Ptr	localSP;
[]
[]	   asm {
[]		   movea.l sp,localSP
[]	   };
[]	   return(localSP);
[] }
[]
[] InitMemory()
[] {
[]	   Ptr	localSP;
[]
[]	   localSP = GetSP();
[]	   SetApplLimit(localSP - STACKSIZE);
[]	   MaxApplZone();
[]
[]	   /* ... etc. ... */
[] }
[]
[] I'm pretty sure that this is the 'right' way to do it (I saw it on
[] comp.sys.mac.programmer :-)), but my application still gets a
[] system error 28 every now and then.

is this equivalent to:

    SetAppLimit(ApplLimit - STACKSIZE);
    MaxApplZone();
    ... 

where ApplLimit is the global assumed to be equal to the result
returned by GetApplLimit() ? (Ref. IM, Vol II, Memory Manager)
The above code fragment clearly adds 8k to the stack space (okay,
i need to brush up on assembly since i don't read it well, yet.
even the simple stuff like movea.l sp, localSP gives me hives).

  -dave-  
hairston@henry.ece.cmu.edu