Why heap is called so?

G

Ganesh

I am not sure if this question is relevant here. Why is 'heap' (the
place where dynamic memory allocation occurs) called so? There is also
a data structure called 'heap'. What is the connection?

Ganesh
 
P

Phlip

Ganesh said:
I am not sure if this question is relevant here.

No, but that's okay.
Why is 'heap' (the
place where dynamic memory allocation occurs) called so? There is also
a data structure called 'heap'. What is the connection?

"Heap" contrasts with "Stack". The latter is a Last-In-First-Out structure,
like a stack of plates. You put new ones on top, and pull them off the top.
You don't (typically) reach into the stack and pull items out of the
middle.

In memory, putting and pulling are allocating and de-allocating.

In a heap, you can reach anywhere into the heap to allocate, and you can
de-allocate in any order, not just the reverse order you allocated.

There is no other reason. If the inventor of the first heap had called it a
"pile", "bag", or "shelf", that's what we would go with to this day.
 
R

Rolf Magnus

Ganesh said:
I am not sure if this question is relevant here. Why is 'heap' (the
place where dynamic memory allocation occurs) called so?

It isn't - at least not in C++. What you are referring to is the free store.
There is also a data structure called 'heap'. What is the connection?

None.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top