What is diff between Heap and free store?

Hi friends,

What is diff between Heap and free store?

I read from here- http://www.gotw.ca/gotw/009.htm
but still not clear.

Please request to reply on this.


akAsh
closed account (z05DSL3A)
That is an interesting question, sort off, in that it is deceptively tricky to answer.

I generally think of the heap (via maloc/free) as a sort of 'raw' material supplier. You ask for a chunk of memory you get it no frills. You have to build any structures yourself.

The Free Store (new/delete) is more like a 'finished goods' supplier. You ask for an object and it gets allocated some space, and the object it built up and prepared for your use. When it is finished with it gets nicely cleaned up.

So the difference is more in the management, that you have no control over, of the space.
thanx Canis to reply.

but what you replied is not so cleared.your talking in very general way.

Please be very specific.

is both are different section in memory or not?

I read some where that initially area used as 'heap' now same area refers as 'free store'.

???
The C++ standard refers to "free store". It does not specify how it is implemented. "heap" is a specific implementation technique. Implementations are free to manage memory as they see fit, although in practice most implementations use a heap. So in most cases, heap and free store are interchangable.

The distinction between malloc/free and new/delete is one of language.
C supports malloc/free but has no concept of new/delete, nor constructors and destructors. C++ introduces the concept of new/delete, constructors and destructors. Because C++ is an extension of C, malloc/free are still available, but are not the C++ way of doing things.

As to whether both refer to the same memory region, that is implementation specific, but in general the answer is yes. Some C++ new/delete implementations will use malloc/free under the covers, some may call OS specific heap management routines if the OS provides them, while other implementations will code new/delete from scratch for efficiency.
hey,
can any one understand this-

Free Store The free store is one of the two dynamic memory
areas, allocated/freed by new/delete. Object
lifetime can be less than the time the storage
is allocated; that is, free store objects can
have memory allocated without being immediately
initialized, and can be destroyed without the
memory being immediately deallocated. During
the period when the storage is allocated but
outside the object's lifetime, the storage may
be accessed and manipulated through a void* but
none of the proto-object's nonstatic members or
member functions may be accessed, have their
addresses taken, or be otherwise manipulated.


Heap The heap is the other dynamic memory area,
allocated/freed by malloc/free and their
variants. Note that while the default global
new and delete might be implemented in terms of
malloc and free by a particular compiler, the
heap is not the same as free store and memory
allocated in one area cannot be safely
deallocated in the other. Memory allocated from
the heap can be used for objects of class type
by placement-new construction and explicit
destruction. If so used, the notes about free
store object lifetime apply similarly here.

So please explain me...
Where did you find that description? It would help to know the context in which you found that description.

Most C++ implementations I am familar with have a single free store using a heap as the implementation technique. That said, certain operating systems have the ability to have multiple storage areas and it is possible in C++ to allocate objects in other than the default heap by overloading the new/delete operators to use alternate storage mechanisms.
closed account (z05DSL3A)
Where did you find that description? It would help to know the context in which you found that description
. See the link on the first post.

------------------------------------------------------------------

C++ : Free-store versus Heap
http://zamanbakshifirst.blogspot.co.uk/2007/02/c-free-store-versus-heap.html

Generally the two terms have been used and abused to the extent that there is no real definitive meaning.

I was told, a long time ago, that the heap is the dynamic memory areas as a whole and the free store was the unallocated portion of this.
Thank you Canis.

As you said following is straight meaning?

> Heap typically as a synonym to "free store"
> usually because they come from a different language background.
Topic archived. No new replies allowed.