Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: 3K "limitation" for CopyBits Summary: Stack space tips. Message-ID: <14041@dartvax.Dartmouth.EDU> Date: 22 Jun 89 17:57:18 GMT References: <3224@ncsuvx.ncsu.edu> <7731@hoptoad.uucp> <669@biar.UUCP> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 51 In article <669@biar.UUCP> trebor@biar.UUCP (Robert J Woodhead) writes: >In article <7731@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes: >>In article <3224@ncsuvx.ncsu.edu> jnh@ecemwl.UUCP (Joseph N. Hall) writes: >>>Does the 3K-byte suggested restriction for CopyBits (mentioned in IM I) >>>still apply? >>I have it on fairly good authority that what happens in CopyBits is >>that each row gets pushed onto the stack. therefore, it is not so much >>the total size of the bitmap, but the width, that determines the >>safety. > >According to something I read many moons ago: > >The 3K limit applies only on 64k ROMS. Later ROMS (and perhaps System Files) >have had QuickDraw patched so that it detects situations where a QD operation >will potentially causes a Stack Heap crash, and ``subdivides'' the operation >into 2 or more subcalls so as to reduce the stack requirements.-- This may be obvious to some, but remember that you can always configure your application to have more or less than the default stack space by using the SetApplLimit() trap call. If you use more, then from what Robert says you would get better performance from operations that have enough stack space to be done in one step. If you don't have an assembler handy, then you could do something like this in MPW C: #define STACKSIZE 20480L /* Or whatever you want. */ main() { int foo,bar; char *heaplimit; /* Last-declared auto variable. */ heaplimit = (char *) (&heaplimit) - STACKSIZE; SetApplLimit(heaplimit); /* * You now have roughly 20k of stack space to play with. */ MaxApplZone(); /* If you need heap space, too. */ /* * The rest of the program is left as an exercise for the reader. */ This technique is better than using the CurStackBase low memory global because it accounts for whatever auto variables are used by main() and its caller. Earle R. Horton "People forget how fast you did a job, but they remember how well you did it." Salada Tag Lines