Path: utzoo!attcan!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!apple!usc!henry.jpl.nasa.gov!elroy.jpl.nasa.gov!jato!mars!baalke From: baalke@mars.jpl.nasa.gov (Ron Baalke) Newsgroups: comp.lang.c Subject: Re: turbo C memory question Message-ID: <2004@jato.Jpl.Nasa.Gov> Date: 25 Oct 89 18:30:34 GMT References: <13042@s.ms.uky.edu> Sender: news@jato.Jpl.Nasa.Gov Reply-To: baalke@mars.UUCP (Ron Baalke) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 36 In article <13042@s.ms.uky.edu> kminor@ms.uky.edu (Kevin R. Minor) writes: > >2. How does Turbo C use memory, in terms of variables and such? > >I guess I should explain what I want to do. I am wanting to create >an array which depends on the RAM of the specific computer. (if the >computer only has 256k, don't allocate as much.) I know that >malloc () will give me the memory I need, but what I'm not sure about >is the overhead of other routines. I have set aside 10,000 bytes >for my stack. Does other memory get used besides the stack, or would >I be safe to allocate the unused RAM for my array? There are 3 areas of memory that Turbo C utilizes. They are the stack, global memory and the heap. The stack size is defaulted to 4K and is mainly used for popping variables into in function calls and is usually sufficient unless you are writing an extremely large program. The stack size can be increased but it is a bit tricky. Global memory is set at 64K and cannot be increased. This is the area where all of your variables are declared outside of a function, normally at the top of the file after the #include statements. This size is set at 64K because that is the size of a segment in the 8088/80286/80386 chips. The heap is all of the memory left over that the stack and global memory doesn't use. (Remember MS-DOS + any TSR's will also be using some of the heap memory). Normally you would use the heap for large memory uses. The only way to access to heap is with the malloc/calloc/realloc/free routines. In your case of setting aside 10,000 bytes you can either declare a global variable, or declare a pointer to the heap by using the malloc and free functions. Ron Baalke | (818) 541-2341 x260 Jet Propulsion Lab M/S 301-355 | baalke@mars.jpl.nasa.gov 4800 Oak Grove Dr. | Pasadena, CA 91109 |