Archived

This topic is now archived and is closed to further replies.

C++'s 'heap' area - definition?

This topic is 5111 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, just a quick question. I''m sure I''ve got the wrong-end-of-the-stick here (so to speak) here... but was wondering if anyone could clarify I know that in C++ memory allocation can be from the ''heap'' area. I''ve just been reading up on some ADT''s and come across the heap ADT - any corrolation? (I couldn''t find it discussed in Stroustrups C++ book).
quote:
A heap is a complete binary tree with the following ordering property: The value of every parent node is greater than or equal to the values of either of its daughter nodes. The largest node is always the root.
Is there any connection between the two? cheers, Jack

Share this post


Link to post
Share on other sites
quote:
The only connection is that usually the C/C++ heap (memory allocated with malloc/new) is actually implemented using a heap algorithm


thats the thing I was curious about. I know that they (on face value) seem to be completely different things... but wondering if the naming of the memory-space was influenced in some way by the ADT.

Jack

Share this post


Link to post
Share on other sites
No, heap and heap are unrelated. period.

One is a tree like data structure, the other is just a name USED to describe the memory allocation method also known as:

heap
free store
arena
anonymous memory

the definition of all these is just that the allocated memory isn''t destroyed by any scope. (see stack)

Share this post


Link to post
Share on other sites
quote:
No, heap and heap are unrelated. period.


quote:
The only connection is that usually the C/C++ heap (memory allocated with malloc/new) is actually implemented using a heap algorithm


hmm, conflicting

ah well.. not that I suppose it matters

Jack

Share this post


Link to post
Share on other sites
quote:
Original post by daerid
Okay, if you want to be picky. It should be "usually implemented", not "actually implemented"


Try "never implemented". The heap is a region of memory allocated to the process beginning directly after the last memory address used for program data.

Under linux, the heap is represented by a pointer to the top of the heap, known as the break value. This value is grown using the brk system call, although that is taken care of by malloc() (new operator).

There is no correlation at all between the tree data structure known as a heap and the region of memory allocated to a process also known a heap (among other names).

EDIT: spelling

[edited by - kevmo on December 15, 2003 8:25:48 PM]

Share this post


Link to post
Share on other sites