为什么在c风格的语言中运行时堆被用于动态内存分配,而数据结构都被称为“堆”?有什么关系吗?


当前回答

The name collision is unfortunate, but not all that mysterious. Heap is a small, common word used to mean a pile, collection, group, etc. The use of the word for the data structure pre-dates (I'm pretty sure) the name of the pool of memory. In fact, pool would have been a much better choice for the latter, in my opinion. Heap connotes a vertical structure (like a pile), which fits with the data structure, but not the memory pool. We don't think of a memory-pool heap as hierarchical, whereas the fundamental idea behind the data structure is keeping the largest element at the top of the heap (and sub-heaps).

堆的数据结构可以追溯到60年代中期;堆积记忆池,70年代初。术语堆(指内存池)至少早在1971年由Wijngaarden在Algol的讨论中使用。

可能最早使用堆作为数据结构是在 威廉姆斯,1964年。“算法232 -堆排序”,ACM通信7(6):347-348

其他回答

也许第一个实现的内存堆是由堆结构管理的?

Donald Knuth说(《计算机编程艺术》,第三版,第1卷,第435页):

1975年左右,一些作者开始将可用内存池称为“堆”。

他没有说哪些作者,也没有给出任何特定论文的参考文献,但他确实说了,与优先级队列相关的术语“堆”的使用是这个词的传统意义。

在我看来,这两个完全不相关的东西有相同的名字只是一个意外/巧合。就像图和图。

它们有相同的名字,但实际上并不相似(甚至在概念上)。内存堆被称为堆,就像你把洗衣篮称为“一堆衣服”一样。这个名字用来表示一个有点混乱的地方,可以随意分配和释放内存。数据结构(正如你参考的维基百科链接所指出的)是完全不同的。

The name collision is unfortunate, but not all that mysterious. Heap is a small, common word used to mean a pile, collection, group, etc. The use of the word for the data structure pre-dates (I'm pretty sure) the name of the pool of memory. In fact, pool would have been a much better choice for the latter, in my opinion. Heap connotes a vertical structure (like a pile), which fits with the data structure, but not the memory pool. We don't think of a memory-pool heap as hierarchical, whereas the fundamental idea behind the data structure is keeping the largest element at the top of the heap (and sub-heaps).

堆的数据结构可以追溯到60年代中期;堆积记忆池,70年代初。术语堆(指内存池)至少早在1971年由Wijngaarden在Algol的讨论中使用。

可能最早使用堆作为数据结构是在 威廉姆斯,1964年。“算法232 -堆排序”,ACM通信7(6):347-348