我也有这个疑问很多年啊,数据结构中的heap应该是历史悠久的,那为啥内存堆也用heap这个词呢?直到我看到这个回答,原来是程序员中的老战斗机Knuth把Heap这个词推广了。
Donald Knuth says (The Art of Computer Programming, Third Ed., Vol. 1, p. 435):Several authors began about 1975 to call the pool of available memory a "heap."
He doesn't say which authors and doesn't give references to any specific papers, but does say that the use of the term "heap" in relation to priority queues is the traditional sense of the word.
但也不是乱用,那时候估计有一些高级语言使用数据结构的Heap或者叫Priority Queue来找到最小可用的内存块。
看这位仁兄的评论:Wikipedia claims that it's because at an early stage Lisp used a heap (data structure) to implement its memory store. It doesn't say how. Its reference is "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest (1990): Introduction to algorithms. MIT Press / McGraw-Hill.", which I don't have.– Steve Jessop
他说早期的Lisp就是使用数据结构堆来做内存池的。
所以也不能说早先两个Heap完全没有关系, 但现在的确是没有任何关系了。