new/malloc & free store/heap

K

Kavya

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.
 
O

Old Wolf

Kavya said:
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.
 
B

Bart

Old Wolf wrote:
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.
 
R

red floyd

Herb Sutter, "Exceptional C++", Item 35, Table 1. He goes into detail
as to why he makes a distinction between the two.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top