7

Can anyone explain why the pool of memory managed by malloc() / free() is called a heap?

Based on [1]: http://www.google.com/url?q=http://gee.cs.oswego.edu/dl/html/malloc.html&sa=D&sntz=1&usg=AFQjCNHaQLotbBKKwYqxiiYWN1146BWzFw "Doug Lea's explanation of how his malloc() works", it's not obvious that the data structure which we call a "heap" is being used at all.

Do we call it a "heap" because it's common for malloc() implementations to use best-fit selection of the memory chunk to return, and that's historically been implemented using a min-heap of chunks, sorted by chunk size?

Luchian Grigore
  • 236,802
  • 53
  • 428
  • 594
Christian Convey
  • 1,072
  • 7
  • 18
  • 3
    The heap memory pool and the heap data structure have nothing to do with each other. – James Jun 11 '13 at 20:42
  • 2
    http://stackoverflow.com/questions/1699057/why-are-two-different-concepts-both-called-heap – Magn3s1um Jun 11 '13 at 20:44
  • 1
    A quick check shows that it is not listed in the index to Knuth volume 1 (which does include dynamic memory management structures). Therefore, it is obviously irrelevant and pointless to ask. – Jerry Coffin Jun 11 '13 at 20:52
  • Also see: [What's the difference between "a" heap and "the" heap?](http://stackoverflow.com/questions/756861/whats-the-relationship-between-a-heap-and-the-heap) – Kninnug Jun 11 '13 at 20:54
  • Because the stack provides a relatively structured allocation area that is governed by scoping rules, and the "rest" of memory is just requested "wherever" and piled about more or less randomly (like heaps of dirty laundry in some college students rooms). – Edwin Buck Jun 11 '13 at 20:56
  • Also note that "the stack" isn't a stack, since you have random access. Every part of RAM is... random access. – Kerrek SB Jun 11 '13 at 20:59
  • **It isn't!** At least, not officially... – autistic Jun 12 '13 at 03:15

0 Answers0