Re: stack vs. heap

Thant Tessman <thant@acm.org>
19 Oct 2005 02:41:00 -0400

          From comp.compilers

Related articles
stack vs. heap shahbazc@gmail.com (falcon) (2005-10-15)
Re: stack vs. heap cjc1@ucs.cam.ac.uk (Chris Cheney) (2005-10-19)
Re: stack vs. heap thant@acm.org (Thant Tessman) (2005-10-19)
RE:stack vs. heap jatin.bhateja@amdocs.com (Jatin Bhateja) (2005-10-20)
| List of all articles for this month |
From: Thant Tessman <thant@acm.org>
Newsgroups: comp.compilers
Date: 19 Oct 2005 02:41:00 -0400
Organization: XMission http://www.xmission.com/
References: 05-10-099
Keywords: storage
Posted-Date: 19 Oct 2005 02:41:00 EDT

falcon wrote:


> This is sort of a silly question but I never took a compiler class and
> every text I read assumes that reader will understand the difference
> between stack space a heap. [...]
>
> Falcon
> [They're both memory, but they're different parts of memory. Stack
> space is quick to allocate and free since it merely involves
> increasing or decreasing the stack and perhaps frame pointer. [...]]


To explain in programmer terms instead of compiler-writer terms, what
makes the difference between stack memory and heap memory is the order
in which chunks of memory are allocated and freed. Stack memory usage
increases and decreases as the program enters and exits functions. The
stack memory in use may grow and shrink indeterminantly, but the last
chunk allocated is always the first chunk freed.


Heap memory increases and decreases with calls to malloc and free. This
means the chunks are allocated and freed in an effectively arbitrary
order. Heap memory usage requires far more bookkeeping than a stack
does. The difference has implementation consequences mentioned by the
moderator.


-thant


--
"We're freaking doomed!" -- The Mogambo Guru


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.