4

At least part of the memory, which is for stuff created by new/malloc, is organized in the form of Heap. I understand the heap is a structure that the parent node is always larger or smaller than its children nodes. It is either a max or min heap.

For the memory organization, what is the key value for building up the heap? in other words, for what type of information or value we are following the heap construction rule (Max/ Min heap)?

Last, what is the advantage of using heap model to organize the memory? Is there good examples or reasons?

trincot
  • 317,000
  • 35
  • 244
  • 286
  • Does this answer your question? [What's the relationship between "a" heap and "the" heap?](https://stackoverflow.com/questions/756861/whats-the-relationship-between-a-heap-and-the-heap) – trincot Aug 10 '21 at 14:32

3 Answers3

4

The heap, in terms of memory, is memory set aside for dynamic allocation. This is completely unrelated with respect to the heap data structure.

influxd
  • 526
  • 3
  • 8
  • I believe this portion of memory "set aside for dynamic allocation" must have been organized or realized following the "heap data structure", otherwise we won't call it "heap". – EngineerDaniel Mar 02 '15 at 00:20
2

It's not.

You are confused about the concept of the heap in memory management(vs stack), and heap, the data structure. They are not related. Specifically, the help memory isn't implemented with the heap data structure.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • Thanks. But if this portion of memory is not realized using the "heap data structure", then what data structure is followed? Why is it called heap, if it is not following the heap data structure? – EngineerDaniel Mar 02 '15 at 00:22
0

The description of the tag you used answers your question:

A heap (data structure) is a tree that is ordered with respect to depth. Heap can also refer to process memory set aside for dynamic allocation.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157