Off Topic: Stack vs. Heap

From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 10/09/03


Date: Wed, 08 Oct 2003 20:48:39 -0700

Kevin Grigorenko wrote:

>
>
> I couldn't find an obvious answer to this in the FAQ. My basic question,
> is: Is there any difference in allocating on the heap versus the stack?
> If heap or stack implementation is not part of the standard, then just
> disregard this question. Here's some questions I'm confused about, and if
> you can add anything else, please do so!
>
> Is the stack limited for each program?
>
> On the other hand, is the heap basically limitless (except of course limited
> to the size of memory or page files)?
>
> If I've got something on the heap, as I understand it, another program can
> update any of my allocated storage without me knowing? Can this happen on
> the stack?
>
> Is there any performance difference in using variables on the stack versus
> on the heap?
>
> Are global and static variables on the stack?
>
> The reason I ask is I'm starting to get into C#, and it makes a big deal
> about allocating a lot of stuff on a garbage collected heap. I wouldn't
> want to start asking off-topic questions, so I'll just ask this: would a
> concept like this follow from the fact that heap storage is better to use
> for some reason rather than storage on the stack?

It depends upon your compiler.
Please tell us which compiler you are using
so that we can redirect to to the appropriate newsgroup.



Relevant Pages

  • Re: storage locations for different data types
    ... and that's why it should be preferred to talk about storage ... or global / heap / stack). ... (Interestingly, temporary objects have automatic storage duration, but ... I remember extensive discussions about the name "heap". ...
    (comp.lang.cpp)
  • Re: Stack vs. Heap
    ... > heap or stack implementation is not part of the standard, ... > about allocating a lot of stuff on a garbage collected heap. ... In C++ use stack objects where you can, use heap objects when you have ...
    (comp.lang.cpp)
  • Re: Statement on Schildt submitted to wikipedia today
    ... storage is allocated from free ... free memory that is used for dynamic allocation is called the heap. ... storage area, and the stack. ...
    (comp.lang.c.moderated)
  • Re: ALLOCATABLE arrays
    ... || If try to create a very large array on the stack and you do not have enough ... || Allocating on the heap gives you access to a hell of a lot more memory (well ... and "heap" (and there probably are/were some computers which don't/didn't ... | Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)
  • Re: ALLOCATABLE arrays
    ... > If try to create a very large array on the stack and you do not have enough ... > Allocating on the heap gives you access to a hell of a lot more memory (well ... Allocatable arrays are allocated on the heap. ... Automatic arrays are always allocated on the stack. ...
    (comp.lang.fortran)