new/malloc & free store/heap

Discussion in 'C++' started by Kavya, Oct 30, 2006.

  1. Kavya

    Kavya Guest

    I always thought heap and free store is same thing but I recently
    starting hearing from people that these are different terms. They say
    new uses free store and malloc/calloc/realloc uses heap.
    Can someone through some light on this issues with some standard
    reference if possible.
     
    Kavya, Oct 30, 2006
    #1
    1. Advertising

  2. Kavya

    Old Wolf Guest

    Kavya wrote:
    > I always thought heap and free store is same thing but I recently
    > starting hearing from people that these are different terms. They say
    > new uses free store and malloc/calloc/realloc uses heap.
    > Can someone through some light on this issues with some standard
    > reference if possible.


    Generally, the two terms are interchangeable, when referring to
    the free store.

    A "heap" is a data structure which is sorted so that each node
    is (greater | less than) all of its children. The term has come to
    be synonymous with free store because traditional memory
    allocators stored the list of free memory blocks in a heap structure.

    However, some people prefer to say "free store" because modern
    memory allocators may not use a heap structure, so it is not
    very accurate to call them a "heap".

    On any particular system, you may or may not find that new and
    malloc allocate memory out of the same memory pool (whatever
    you might call that pool). They might do, or they might not. Which
    is why you should be careful to match new with delete, and malloc
    with free.
     
    Old Wolf, Oct 30, 2006
    #2
    1. Advertising

  3. Kavya

    Bart Guest

    Old Wolf wrote:
    <snip>
    > On any particular system, you may or may not find that new and
    > malloc allocate memory out of the same memory pool (whatever
    > you might call that pool). They might do, or they might not. Which
    > is why you should be careful to match new with delete, and malloc
    > with free.


    The main reason to match calls to new with calls to delete, however, is
    so that constructors and destructors are called correctly.

    Regards,
    Bart.
     
    Bart, Oct 30, 2006
    #3
  4. Kavya

    red floyd Guest

    Old Wolf wrote:
    > Kavya wrote:
    >> I always thought heap and free store is same thing but I recently
    >> starting hearing from people that these are different terms. They say
    >> new uses free store and malloc/calloc/realloc uses heap.
    >> Can someone through some light on this issues with some standard
    >> reference if possible.

    >


    Herb Sutter, "Exceptional C++", Item 35, Table 1. He goes into detail
    as to why he makes a distinction between the two.
     
    red floyd, Oct 30, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    13
    Views:
    723
  2. ravi
    Replies:
    0
    Views:
    469
  3. Peter
    Replies:
    34
    Views:
    2,023
    Richard Tobin
    Oct 22, 2004
  4. Michal Slocinski

    Heap dump file size vs heap size

    Michal Slocinski, Mar 25, 2008, in forum: Java
    Replies:
    1
    Views:
    766
    GArlington
    Mar 25, 2008
  5. Replies:
    5
    Views:
    162
Loading...

Share This Page