Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the heap actually a heap? [duplicate]

Tags:

Possible Duplicates:
Why are two different concepts both called “heap”?
What's the relationship between “a” heap and “the” heap?

In .NET (and Java as far as I know), the area where objects are dynamically allocated is referred to as the managed heap. However, most documentation that describes how the managed heap works depicts it as a linear data structure, such as a linked list or stack.

So, is the managed heap actually a heap, or is it implemented with some other data structure? If it actually does not use a heap data structure, is seems like a significant failure of terminology to overload the meaning of this word.

If it is in fact a heap data structure, what is the value that satisfies the heap property: the size of the allocated memory region?

like image 758
newdayrising Avatar asked Jan 08 '11 19:01

newdayrising


People also ask

Is heap memory implemented as a heap?

If the program doesn't free heap memory it runs out of it (or heap space). There are different data structures for heap implementation some of them are binary tree derivatives, some are not e.g. Fibonacci Heap (forrest of trees).

Is heap memory a tree?

In computer science, a heap is a specialized tree-based data structure which is essentially an almost complete tree that satisfies the heap property: in a max heap, for any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C.

What is the memory heap?

A memory heap is a location in memory where memory may be allocated at random access. Unlike the stack where memory is allocated and released in a very defined order, individual data elements allocated on the heap are typically released in ways which is asynchronous from one another.

How is the heap memory implemented?

Heaps are used for dynamically allocating memory regions in course of a program execution. The program releases the memory back to heap once it is done with the usage of the memory. Heaps are usually implemented by the underlying platform usually an OS.


2 Answers

No, the heap is not a heap-ordered binomial tree at all. It's not clear (to me) whose fault the terminology clash is, but both uses of heap date back decades now (mid-1970, it appears). Some of the history is discussed in this article.

like image 75
Martin v. Löwis Avatar answered Sep 23 '22 00:09

Martin v. Löwis


I certainly don't have the historical knowledge to comment on this with any authority, but I believe the term "heap" as employed to describe the memory allocation mechanism for longer-lived objects in .NET and Java is more intended as an evocative, descriptive word—like, this big unstructured (from the dev's viewpoint) mass of memory where stuff lives. The "stack" in contrast evokes the image of a much more structured region of data (again, from the dev's viewpoint): "where" things live on the stack feels a lot more relevant than "where" they live on the heap.

This is clearly very different from the actual heap data structure, which uses the word "heap" to refer to the so-called heap property (from Wikipedia):

if B is a child node of A, then key(A) ≥ key(B).

So yeah, they're actually unrelated. One is just a descriptive term whereas the other has a much more formal definition.

like image 43
Dan Tao Avatar answered Sep 22 '22 00:09

Dan Tao