turbo C memory question

Ron Baalke baalke at mars.jpl.nasa.gov
Thu Oct 26 04:30:34 AEST 1989


In article <13042 at s.ms.uky.edu> kminor at 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 at mars.jpl.nasa.gov
 4800 Oak Grove Dr.               |
 Pasadena, CA 91109               |



More information about the Comp.lang.c mailing list