Thread: stach and heap.

  1. #1
    Unregistered
    Guest

    stach and heap.

    Hi guys. need some help with stack and heap.

    1.Please define stack and heap: I think at the moment the stack is all the memory a program need ie. if my program has int x,y then the stack size is 4 (bytes) is this correct?

    2. the heap is all the memory above/beyond the stack that has been allocated by the operating system when my compiler was loaded is this correct?

    3. the space managed in the heap may not be contiguous and the free storage is kept as a list of free blocks.

    thanks for all the help.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    I had a fairly large post on this recently...
    http://www.cprogramming.com/cboard/s...&threadid=9358

    1.Please define stack and heap: I think at the moment the stack is all the memory a program need ie. if my program has int x,y then the stack size is 4 (bytes) is this correct?
    This obviously depends on how big each int is, but if each int is 2 bytes large, then yes,
    int x, y;
    will make room for 4 bytes on the stack.
    2. the heap is all the memory above/beyond the stack that has been allocated by the operating system when my compiler was loaded is this correct?
    Yea, pretty much.
    3. the space managed in the heap may not be contiguous and the free storage is kept as a list of free blocks.
    Exactly.

    vVv: Variables with automatic storage (pretty much anything but globals) use the stack.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed