Re: difference between stack & heap (general, for a newbie)

From: Sean Cook (news_at_ghink.com)
Date: 01/27/04


Date: 27 Jan 2004 07:47:41 -0800

Andrey (and others),

I now see that my question was far too ambiguous. I understand the
difference between std::stack and std::heap as far as looking at each
of those data structures as abstract data types, I just do not
understand how these two data structures are implemented when your C++
code is compiled.

What I should've asked is "what is the scope of data when allocated
from the heap, and what is the scope of data when allocated from the
stack (where ``heap'' and ``stack'' are not standards, but are merely
common terms.)

And also, is there a performance difference, in general, of objects
allocated on the stack versus those allocated on the heap, or is this
a completely meaningless question?

Thanks.
Sean

Andrey Tarasevich <andreytarasevich@hotmail.com> wrote in message news:<101b7n8gm0fnk76@news.supernews.com>...
> Sean Cook wrote:
> > ...
> > can anyone give me a good, thorough explanation of the difference
> > between the heap and the stack in C++?
> > ...
>
> Your question is too ambiguous to be answered right away.
>
> There are data structures called 'stack' (see 'std::stack') and 'heap'
> (see 'std::make_heap').
>
> There are memory types commonly referred to as 'stack' and 'heap'
> (although these terms are unofficial or semi-official in C++ world).
>
> Would you please clarify what your question is about?



Relevant Pages

  • Re: How does managed code work?
    ... Does it work the same way as the native stack with a frame pointer that is the head of a linked list of stack frames where each time we enter a function we create a new stack frame in which new variables are pushed and each time we exit a function the entire stack frame is popped? ... Can someone point me to a discussion of the managed heap? ... How does it prevent memory leaks that occur in COM when two objects reference each other and keep the others reference count nonzero? ... Because objects don't go out of scope, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Stack vs. Heap
    ... Typically, if an element does not need to exist beyond the scope of its variable, you are ... much better off allocating it on the stack instead of the heap. ... have a lifetime beyond the local scope must be allocated on the heap. ...
    (microsoft.public.vc.mfc)
  • Re: stack vs. heap. a loaded question.
    ... > I am writing a program which needs to run as quickly as possible, ... > memory to even consider putting most/all of it on the stack? ... > of very large data structures. ... I have always used the heap. ...
    (comp.lang.cpp)
  • Re: difference between stack & heap (general, for a newbie)
    ... The stack is used to allocate temporary objects while the heap is used by a ... an object in a heap is not scope ... an object on the stack is ... destroyed automatically when its scope ends. ...
    (comp.lang.cpp)
  • Re: finalize() not guaranteed to be called -- ever
    ... so objects never have a scope. ... The Jet compiler puts some objects on the stack so they automatically ... this stack called the nursery. ... are still "live" are moved to the heap. ...
    (comp.lang.java.programmer)