19

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?

Community
  • 1
  • 1
newdayrising
  • 3,662
  • 3
  • 22
  • 29

4 Answers4

17

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.

Martin v. Löwis
  • 115,074
  • 16
  • 187
  • 226
  • 1
    Possibly the word heap has taken on meaning of its own beyond the data structure as conventional terminology. I mean, what else would we call it and how would we teach it without calling it "heap"? – John K Jan 08 '11 at 19:51
  • 1
    +1 for the historical reference from the The Art of Computer Programming. – CARLOS LOTH Jan 08 '11 at 19:52
  • @John K: I'm not a native speaker (of English), so "heap" doesn't mean much to me, except for the two disjoint uses in computing. IIUC, the conventional use is synonymous to "pile". – Martin v. Löwis Jan 08 '11 at 19:53
1

In this sense, "heap" means: a special memory area used for store important resources. In that context it is not related to the "heap data strucure".

CARLOS LOTH
  • 4,353
  • 3
  • 35
  • 40
1

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.

Dan Tao
  • 119,009
  • 50
  • 280
  • 431
0

I'm not sure my answer, but as far as i know in languages like C# or Java, where memory is managed my Garbage Collector the memory region is not linear. The GC is freeing the memory that can free and when the memory is low it compacts the memory doing some kind of defragmentation. It moves blocks of memory that program uses to make some space in "the end". Why you need this answer? Do you want to make some low-level memory management?

Mat
  • 2,071
  • 2
  • 23
  • 33