Path: utzoo!utgpu!watmath!att!bellcore!rutgers!mailrus!cs.utexas.edu!usc!apple!oliveb!amiga!cbmvax!daveh From: daveh@cbmvax.UUCP (Dave Haynie) Newsgroups: comp.sys.amiga Subject: Re: Is she c:Stack'd Message-ID: <8053@cbmvax.UUCP> Date: 2 Oct 89 16:22:56 GMT References: <3944@m2-net.UUCP> Organization: Commodore Technology, West Chester, PA Lines: 68 in article <3944@m2-net.UUCP>, ba@m2-net.UUCP (Bill Allen) says: > "Up your stack..." > What causes certain prgs to work just fine in 4K of stack > (or less) while others need 10K? I've seen several that > require 20K, 30K, 40K. Can other programming techniques be > used to prevent this? The difference usually amounts to something like this: // Stack Wasting Example void thing1(void) { char temporary[200000]; // Do the interesting stuff } // Doesn't waste stack void thing2(void) { char *temporary = malloc(200000); // Do the interesting stuff free(temporary); } // Doesn't waste stack void thing3(void) { static char temporary[200000]; // Do the interesting stuff } These functions would each do the same thing, only the first allocates it's temporary buffer on the stack, and would take 200,000 bytes of stack memory to run, the second allocates it's temporary buffer from the memory pool upon entry to the function, and returns that memory upon exit. The third function allocates that temporary statically, for the life of the program. That doesn't take stack memory, but it might take more system memory at any given time than absolutely necessary, and of course will cause trouble if the programmer expected a new "temporary" to be allocated upon each entry to the function (often the case if you're using recursion). The programmer should be sentitive to this. Small allocations on the stack are certainly no problem, but large ones are. In most, though not every case, programs that use lots of stack could be using less with more clever programming. > Is this "poor" programming or are there legitimate needs for unavoidable > minimum 60,000+ byte stack. Chances are, that programmer never even thought about how much stack was being used. > --------------------------------------------------------- > Reply-To: ba@m2-net.UUCP (Bill Allen Beogelein) M-NET, Ann Arbor, MI > or call Sharewarer's BBS at 313-473-2020 24hrs, PCP thru MIDET, 100% Amiga > --------------------------------------------------------- -- Dave Haynie Commodore-Amiga (Systems Engineering) "The Crew That Never Rests" {uunet|pyramid|rutgers}!cbmvax!daveh PLINK: hazy BIX: hazy Too much of everything is just enough