Path: utzoo!mnetor!lazer From: lazer@mnetor.UUCP (Lazer Danzinger) Newsgroups: comp.lang.c Subject: Re: What goes on stack? Message-ID: <4757@mnetor.UUCP> Date: 21 Oct 88 15:19:25 GMT References: <3221@sdsu.UUCP> Reply-To: lazer@mnetor.UUCP (Lazer Danzinger) Organization: Motorola Computer X Lines: 45 In article <3221@sdsu.UUCP> roetzhei@sdsu.UCSD.EDU (William Roetzheim) writes: > > Help! I'm working with Turbo C version 1.5. My program is large (about >30,000 lines) and deals with large arrays (static and dynamic) and many >string literals in the code. The stack size required is huge. Anything >less than about 55K for a stacksize causes a stack overflow on program >execution. > > Other than return addresses, register values, and paramaters, what else >does Turbo C put on the stack? What the heck would cause it to grow so >big? > As far as I know, it is not at all uncommon (perhaps, even standard practice) for all dynamic variables, including "large (dynamic) arrays" to be allocated from stack space. This is very likely your problem. Depending on the particulars, the following may be possible solutions: 1. Allocate memory for dynamic variables (your large arrays) at run-time, using a routine like malloc. Then free the storage at the end of the module. 2. (This is a little ugly: ) If speed is not too much of an issue, try using disk storage instead of memory. 3. Check your Turbo manual to find out if there is a way of specifying a larger stack size. 4. Although string literals do not come off the stack, if you are using the same literals more than once, it is a good practice to strcpy them into externs. This, besides conserving sometimes oodles of space, also makes program modification a lot easier. -- ----------------------------------------------------------------------------- Lazer Danzinger | "Ben Zoma said, 'Who is wise? One who learns from lazer@mnetor | every person...Who is courageous? One who conquers | his [evil] inclination...Who is wealthy? One who is | satisfied with his portion...Who is respected? One who (416) 475-8980 | respects his fellow man...'" -- Avot 4:1 ----------------------------------------------------------------------------