[prog] guide to memory in C, the stack, heap?

Aslı gosalyn at gmail.com
Thu Feb 16 04:47:50 EST 2006


hi angelina,


"But something struck me as odd, it tells me the stack is "filled as
needed from the bottom to the top" but then ends by telling me all
elements are added and removed only from the top. "

i can this would help you have a better understanding of the stack thing..

stacks are accessed by pushing and popping. but when you push a variable to
the stack, you push it from the topmost, i mean, you put it on top of the
highest element. and likely, when you pop a variable from the stack, you
remove it from the top, so when you remove,  the variable that was once
under your popped variable, now becomes the top one, and when you make
another pop, you'll get that variable..

and it's a classical example, but you can think of a stack of
dishes..normally, you begin building the stack from the bottom to the top,
and then when you need a dish, you take the topmost one..and when you put
another dish, you just put it on the top of your current stack..

well, my mother tongue is not english so i'm not sure if i could explain it
well, but i hope it helps..

good luck:)

aslı

On 15/02/06, Angelina Carlton <brat at magma.ca> wrote:
>
>
> Hello
>
> My C book barely touches on the stack and the heap and what really goes
> on during function calls like malloc and free.
>
> So I decided to look for a website that explains this. Google turned up
> lots of hits and I started reading this page:
>
> ,----[ http://www.coronadoenterprises.com/extras/diagram.html ]
> | Stack - The area that looks like a ladder on the right part of the
> | diagram is the stack. The stack is allocated by the system to be a fixed
> | size and is filled as needed from the bottom to the top one element at a
> | time. Elements are removed from the top to the bottom one element at a
> | time. Thus the last element added to the stack is the first element that
> | is removed when no longer needed. Any element on the stack is
> | potentially available for reference or modification by the executing
> | code, but elements are added and removed only from the top.
> `----
>
> But something struck me as odd, it tells me the stack is "filled as
> needed from the bottom to the top" but then ends by telling me all
> elements are added and removed only from the top.
>
> I was wondering if anyone has a better explanation in their bookmarks?
>
> --
> -----Angelina Carlton-----
> orchid on irc.freenode.net
>      brat at magma.ca
> web:bzgirl.bakadigital.com
> --------------------------
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming
>


More information about the Programming mailing list