Stacks and heaps

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sathyaish

    #1

    Stacks and heaps

    I've searched Google and found a few, but I am not so satisfied. Any
    good reading on "stacks and heaps" about how and when memory is
    allocated from the heap?
  • Jack Klein

    #2
    Re: Stacks and heaps

    On 2 Jun 2004 21:14:19 -0700, VisualBasicLear ner@yahoo.com (Sathyaish)
    wrote in comp.lang.c:
    [color=blue]
    > I've searched Google and found a few, but I am not so satisfied. Any
    > good reading on "stacks and heaps" about how and when memory is
    > allocated from the heap?[/color]

    The C standard does not specify mechanisms like stacks and heaps.
    Memory has three types of storage duration in C programs, static,
    automatic, and dynamic.

    When, how, and why an implementation provides and manages these types
    of memory is up to the implementation. So if you are interested in
    how a specific compiler manages memory, you need to ask in a compiler
    specific support group.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.l earn.c-c++

    Comment

    • Dan Pop

      #3
      Re: Stacks and heaps

      In <gubtb05147f6jc qa035va6kf47h8j 7npmg@4ax.com> Jack Klein <jackklein@spam cop.net> writes:
      [color=blue]
      >On 2 Jun 2004 21:14:19 -0700, VisualBasicLear ner@yahoo.com (Sathyaish)
      >wrote in comp.lang.c:
      >[color=green]
      >> I've searched Google and found a few, but I am not so satisfied. Any
      >> good reading on "stacks and heaps" about how and when memory is
      >> allocated from the heap?[/color]
      >
      >The C standard does not specify mechanisms like stacks and heaps.[/color]

      These are data structures, not mechanisms.
      [color=blue]
      >Memory has three types of storage duration in C programs, static,
      >automatic, and dynamic.
      >
      >When, how, and why an implementation provides and manages these types
      >of memory is up to the implementation. So if you are interested in
      >how a specific compiler manages memory, you need to ask in a compiler
      >specific support group.[/color]

      There is nothing compiler specific in understanding how these data
      structures can be used to implement automatic and dynamic memory
      allocation.

      Dan
      --
      Dan Pop
      DESY Zeuthen, RZ group
      Email: Dan.Pop@ifh.de

      Comment

      • Thomas Matthews

        #4
        Re: Stacks and heaps

        Sathyaish wrote:[color=blue]
        > I've searched Google and found a few, but I am not so satisfied. Any
        > good reading on "stacks and heaps" about how and when memory is
        > allocated from the heap?[/color]

        Often times, compilers use a heap for managing dynamic memory.
        Dynamic memory is memory that is set aside for the program to
        use during run-time.

        Most of the time, programs use the *alloc() family of functions
        to allocate from dynamic memory. The memory stays allocated until
        either the program deallocates the memory via free or the
        program is terminated (and the memory is re-used by the operating
        system).

        Dynamic memory often is used when the amount cannot be determined
        during compile time, or when the program needs more memory than
        the compiler can allocate during compile time (or program load
        time).

        Linked lists are a classic example of using dynamic memory
        allocation.

        --
        Thomas Matthews

        C++ newsgroup welcome message:

        C++ Faq: http://www.parashift.com/c++-faq-lite
        C Faq: http://www.eskimo.com/~scs/c-faq/top.html
        alt.comp.lang.l earn.c-c++ faq:

        Other sites:
        http://www.josuttis.com -- C++ STL Library book

        Comment

        • Sathyaish

          #5
          Re: Stacks and heaps

          Thanks, Thomas and others. I want some more rigorous reading on this.
          For instance, I could easily understand what Thomas Matthews said
          because I knew it earlier plus I have some background of C and C++.
          Where can I get more copious information on the internal working of
          the heap?

          PS: Thomas, haven't I seen you on JoS?

          Comment

          • Thomas Matthews

            #6
            Re: Stacks and heaps

            Sathyaish wrote:[color=blue]
            > Thanks, Thomas and others. I want some more rigorous reading on this.
            > For instance, I could easily understand what Thomas Matthews said
            > because I knew it earlier plus I have some background of C and C++.
            > Where can I get more copious information on the internal working of
            > the heap?[/color]

            The heap is a tool (data structure) used by some compiler vendors to
            manage dynamic memory. An implementation is not required to have
            a heap in order to be compliant with the standard.

            The question now is whether you want copious information about:
            1. Heap data structures
            2. Memory allocation methods (schemes)
            3. Compiler Theory.
            I suggest using your favorite web search engine with the appropriate
            keywords and see what you can find. I took and older route and took
            classes in the above at the University. Many Universities give the
            Computer Science people a Compiler to write as their final project.

            As far as the C language goes, you can do three things with
            dynamic memory:
            1. Allocate from it.
            2. Reallocate from it.
            2. Deallocate objects to it (i.e. return or free already
            allocated items).
            Kind of simple and boring. You allocate memory as you need it
            and dispose of the objects when you are finished with them.
            Anything beyond this, such as alignment and memory collection,
            is beyond the scope of this newsgroup.

            [color=blue]
            >
            > PS: Thomas, haven't I seen you on JoS?[/color]
            What is JoS?
            I remember playing with an operating system called JOSS, but
            that was a long time ago.

            If you know me, you might remember that I really hate acroynyms.
            Just as a picture is worth a thousand words, one never really
            knows which of those thousand words the author/artist was meaning
            to convey. I prefer to be explicit. So, WTF is JoS?


            --
            Thomas Matthews

            C++ newsgroup welcome message:

            C++ Faq: http://www.parashift.com/c++-faq-lite
            C Faq: http://www.eskimo.com/~scs/c-faq/top.html
            alt.comp.lang.l earn.c-c++ faq:

            Other sites:
            http://www.josuttis.com -- C++ STL Library book

            Comment

            • Sathyaish

              #7
              Re: Stacks and heaps

              That answers it. The Joel On Software site, a wonderful site about
              software development issues, is more fondly known by its members as
              JoS. Thanks for the info. I wish I'd gone to a university for a
              Computer Science degree when my parents couldn't afford to send me.

              Regards,
              Sathyaish Chakravarthy.



              Thomas Matthews <Thomas_Matthew sSpitsOnSpamBot s@sbcglobal.net > wrote in message news:<fM2wc.66$ rU6.62@newssvr1 6.news.prodigy. com>...[color=blue]
              > Sathyaish wrote:[color=green]
              > > Thanks, Thomas and others. I want some more rigorous reading on this.
              > > For instance, I could easily understand what Thomas Matthews said
              > > because I knew it earlier plus I have some background of C and C++.
              > > Where can I get more copious information on the internal working of
              > > the heap?[/color]
              >
              > The heap is a tool (data structure) used by some compiler vendors to
              > manage dynamic memory. An implementation is not required to have
              > a heap in order to be compliant with the standard.
              >
              > The question now is whether you want copious information about:
              > 1. Heap data structures
              > 2. Memory allocation methods (schemes)
              > 3. Compiler Theory.
              > I suggest using your favorite web search engine with the appropriate
              > keywords and see what you can find. I took and older route and took
              > classes in the above at the University. Many Universities give the
              > Computer Science people a Compiler to write as their final project.
              >
              > As far as the C language goes, you can do three things with
              > dynamic memory:
              > 1. Allocate from it.
              > 2. Reallocate from it.
              > 2. Deallocate objects to it (i.e. return or free already
              > allocated items).
              > Kind of simple and boring. You allocate memory as you need it
              > and dispose of the objects when you are finished with them.
              > Anything beyond this, such as alignment and memory collection,
              > is beyond the scope of this newsgroup.
              >
              >[color=green]
              > >
              > > PS: Thomas, haven't I seen you on JoS?[/color]
              > What is JoS?
              > I remember playing with an operating system called JOSS, but
              > that was a long time ago.
              >
              > If you know me, you might remember that I really hate acroynyms.
              > Just as a picture is worth a thousand words, one never really
              > knows which of those thousand words the author/artist was meaning
              > to convey. I prefer to be explicit. So, WTF is JoS?
              >
              >
              > --
              > Thomas Matthews
              >
              > C++ newsgroup welcome message:
              > http://www.slack.net/~shiva/welcome.txt
              > C++ Faq: http://www.parashift.com/c++-faq-lite
              > C Faq: http://www.eskimo.com/~scs/c-faq/top.html
              > alt.comp.lang.l earn.c-c++ faq:
              > http://www.raos.demon.uk/acllc-c++/faq.html
              > Other sites:
              > http://www.josuttis.com -- C++ STL Library book[/color]

              Comment

              Working...