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

Started by
7 comments, last by jollyjeffers 20 years, 4 months ago
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Advertisement
they are two different meanings of the word "heap"... one is an ADT, and the other is memory you allocate with "new".
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
The only connection is that usually the C/C++ heap (memory allocated with malloc/new) is actually implemented using a heap algorithm
daerid@gmail.com
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

quote:Original post by jollyjeffers
but wondering if the naming of the memory-space was influenced in some way by the ADT.


The proper term for "the heap" is arena.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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)
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Okay, if you want to be picky. It should be "usually implemented", not "actually implemented"
daerid@gmail.com
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]

This topic is closed to new replies.

Advertisement