“a”堆和“堆”之间的关系是什么?

时间:2023-01-23 23:44:08

A heap is a tree data structure where higher levels of the tree always contain greater (or lesser, if it's set up that way) values than lower levels. "The" heap is a bunch of free RAM that a program has available for dynamic allocation. They're both called "heap," but what does the one have to do with the other?

堆是树数据结构,其中树的较高级别总是包含比较低级别更大(或更小,如果它设置的那样)值。 “堆”是一堆程序可用于动态分配的空闲RAM。它们都被称为“堆”,但是那个与另一个有什么关系呢?

9 个解决方案

#1


Nothing much, to be honest. I would imagine that the word heap was simply taken with it's everday (non-technical) usage and applied to these two concepts individually as reasonably good analogies.

没什么,说实话。我认为单词heap只是简单地用它来进行日常(非技术)用法,并且单独应用于这两个概念作为合理的类比。

In the first case (tree data structure meaning), the description heap is most appropiate because "greater" objects are placed higher up in the tree (where "greater" is determined by an arbitrary key function) - i.e. there's a sort of piling of smaller objects on top of larger ones (or larger on top, depending how you think of it). This is just how I'd interpret it; whoever first applied the name heap to this data-structure thought it was an appropiate name in his mind, and it's just stuck.

在第一种情况下(树数据结构意义),描述堆是最合适的,因为“更大”的对象放在树中更高的位置(其中“更大”由任意键函数确定) - 即有一种堆积较大的物体(或较大的物体在顶部,取决于您的想法)。这就是我解释它的方式;无论谁首先将名称堆应用于此数据结构,都认为它在他的脑海中是一个合适的名称,而且它只是卡住了。

In the second case (chunks of RAM), the name of heap is maybe a bit more evident. "Heap" is just "a large collection of things in a highly arbitrary order" here, which would seem to apply just as well in common usage as it does to dynamically allocated chunks of memory.

在第二种情况下(RAM的块),堆的名称可能更明显一些。 “Heap”在这里只是“一个高度随意的顺序的大量集合”,这似乎适用于通用用法,就像动态分配内存块一样。

In any case, I wouldn't worry about the abstract metaphorical similarities you can draw between the two ideas. Treat them completely seperately and you won't go wrong in any situation.

在任何情况下,我都不会担心你可以在两个想法之间画出抽象的隐喻相似之处。完全单独对待它们,在任何情况下都不会出错。

Edit: It seems the tree-based data structure may have taken its name from the heap of abstract algebra, as is reasonably common within computer science. However, I wouldn't want to confirm or deny this...

编辑:似乎基于树的数据结构可能已经从抽象代数堆中取名,这在计算机科学中是相当普遍的。但是,我不想确认或否认这一点......

#2


See this very site for an exploration of the origin of the name "heap" for the free store of memory.

请参阅此站点以了解内存的免费存储库名称“heap”的来源。

#3


They both have the same name, that's about it.
There 'the heap' is never arranged as an actual heap data structure.

它们都有相同的名称,就是它。 “堆”永远不会被安排为实际的堆数据结构。

#4


The heap (datastructure) is called like that because if you draw it it looks like a heap. The heap (memory) is called a heap because it is somehow organized but not fully. You accumulate data on a heap but you might have holes in it and irregularities. It's as if you'd put papers on a heap. Sometimes you remove one from the bottom. This has a form of a heap, i.e. somehow organized but not fully.

堆(datastructure)被调用,因为如果你绘制它,它看起来像一个堆。堆(内存)被称为堆,因为它以某种方式组织但不完全。您在堆上累积数据,但可能有漏洞和不规则。就好像你把文件放在堆里一样。有时您从底部删除一个。这有一种形式的堆,即以某种方式组织但不完全。

#5


The only relationship between the two is the name "heap."

两者之间唯一的关系是名称“堆”。

#6


They...have the same name! That's it.

他们......有同样的名字!而已。

#7


Nothing. No relation.

没有。没关系。

#8


To futher complicate the question: on some systems (e.g. Microsoft Windows), there are multiple "heaps" in the memory allocation sense. "The" heap is merely the default heap. But if you call HeapAlloc(), you can choose from which memory allocation you want a sub-allocation.

更进一步使问题复杂化:在某些系统(例如Microsoft Windows)上,内存分配意义上存在多个“堆”。 “”堆只是默认堆。但是如果你调用HeapAlloc(),你可以选择你想要子分配的内存分配。

#9


Definition from answers.com

来自answers.com的定义

Heap: A group of things placed or thrown, one on top of the other: a heap of dirty rags lying in the corner.

堆:放置或抛出的一组东西,一个放在另一个上面:一堆脏衣服放在角落里。

It's just basic naming due to the conceptual image of throwing things in an unordered fashion. As other posters point out, the heap is not organized as a heap data structure. That depends on the memory allocation routines in your system library (eg. check how malloc works)

这只是基本的命名,因为以无序的方式扔东西的概念图像。正如其他海报所指出的那样,堆不是作为堆数据结构组织的。这取决于系统库中的内存分配例程(例如,检查malloc的工作原理)

#1


Nothing much, to be honest. I would imagine that the word heap was simply taken with it's everday (non-technical) usage and applied to these two concepts individually as reasonably good analogies.

没什么,说实话。我认为单词heap只是简单地用它来进行日常(非技术)用法,并且单独应用于这两个概念作为合理的类比。

In the first case (tree data structure meaning), the description heap is most appropiate because "greater" objects are placed higher up in the tree (where "greater" is determined by an arbitrary key function) - i.e. there's a sort of piling of smaller objects on top of larger ones (or larger on top, depending how you think of it). This is just how I'd interpret it; whoever first applied the name heap to this data-structure thought it was an appropiate name in his mind, and it's just stuck.

在第一种情况下(树数据结构意义),描述堆是最合适的,因为“更大”的对象放在树中更高的位置(其中“更大”由任意键函数确定) - 即有一种堆积较大的物体(或较大的物体在顶部,取决于您的想法)。这就是我解释它的方式;无论谁首先将名称堆应用于此数据结构,都认为它在他的脑海中是一个合适的名称,而且它只是卡住了。

In the second case (chunks of RAM), the name of heap is maybe a bit more evident. "Heap" is just "a large collection of things in a highly arbitrary order" here, which would seem to apply just as well in common usage as it does to dynamically allocated chunks of memory.

在第二种情况下(RAM的块),堆的名称可能更明显一些。 “Heap”在这里只是“一个高度随意的顺序的大量集合”,这似乎适用于通用用法,就像动态分配内存块一样。

In any case, I wouldn't worry about the abstract metaphorical similarities you can draw between the two ideas. Treat them completely seperately and you won't go wrong in any situation.

在任何情况下,我都不会担心你可以在两个想法之间画出抽象的隐喻相似之处。完全单独对待它们,在任何情况下都不会出错。

Edit: It seems the tree-based data structure may have taken its name from the heap of abstract algebra, as is reasonably common within computer science. However, I wouldn't want to confirm or deny this...

编辑:似乎基于树的数据结构可能已经从抽象代数堆中取名,这在计算机科学中是相当普遍的。但是,我不想确认或否认这一点......

#2


See this very site for an exploration of the origin of the name "heap" for the free store of memory.

请参阅此站点以了解内存的免费存储库名称“heap”的来源。

#3


They both have the same name, that's about it.
There 'the heap' is never arranged as an actual heap data structure.

它们都有相同的名称,就是它。 “堆”永远不会被安排为实际的堆数据结构。

#4


The heap (datastructure) is called like that because if you draw it it looks like a heap. The heap (memory) is called a heap because it is somehow organized but not fully. You accumulate data on a heap but you might have holes in it and irregularities. It's as if you'd put papers on a heap. Sometimes you remove one from the bottom. This has a form of a heap, i.e. somehow organized but not fully.

堆(datastructure)被调用,因为如果你绘制它,它看起来像一个堆。堆(内存)被称为堆,因为它以某种方式组织但不完全。您在堆上累积数据,但可能有漏洞和不规则。就好像你把文件放在堆里一样。有时您从底部删除一个。这有一种形式的堆,即以某种方式组织但不完全。

#5


The only relationship between the two is the name "heap."

两者之间唯一的关系是名称“堆”。

#6


They...have the same name! That's it.

他们......有同样的名字!而已。

#7


Nothing. No relation.

没有。没关系。

#8


To futher complicate the question: on some systems (e.g. Microsoft Windows), there are multiple "heaps" in the memory allocation sense. "The" heap is merely the default heap. But if you call HeapAlloc(), you can choose from which memory allocation you want a sub-allocation.

更进一步使问题复杂化:在某些系统(例如Microsoft Windows)上,内存分配意义上存在多个“堆”。 “”堆只是默认堆。但是如果你调用HeapAlloc(),你可以选择你想要子分配的内存分配。

#9


Definition from answers.com

来自answers.com的定义

Heap: A group of things placed or thrown, one on top of the other: a heap of dirty rags lying in the corner.

堆:放置或抛出的一组东西,一个放在另一个上面:一堆脏衣服放在角落里。

It's just basic naming due to the conceptual image of throwing things in an unordered fashion. As other posters point out, the heap is not organized as a heap data structure. That depends on the memory allocation routines in your system library (eg. check how malloc works)

这只是基本的命名,因为以无序的方式扔东西的概念图像。正如其他海报所指出的那样,堆不是作为堆数据结构组织的。这取决于系统库中的内存分配例程(例如,检查malloc的工作原理)