JVM note2

本文详细解释了计算机科学中堆(heap)与栈(stack)的概念及它们之间的区别。通过类比的方式,帮助读者理解这两种数据结构的特点:栈遵循后进先出的原则,而堆则没有固定的取出顺序。此外,还探讨了两者在内存管理方面的不同之处。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

 

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.' But in the present series of books, we will use that word only in its more traditional sense related to priority queues.

 

 

"The" heap is a bunch of free RAM that a program has available for dynamic allocation.

 

还有两幅形象的图片对比heap和stack

 

  • stack(In a stack of items, items sit one on top of the other in the order they were placed there, and you can only remove the top one (without toppling the whole thing over).)

  • heap(In a heap, there is no particular order to the way items are placed. You can reach in and remove items in any order because there is no clear 'top' item.)

 

 

从百度百科上看到一句话,“由于Stack的内存管理是顺序分配的,而且定长,不存在内存回收问题;而Heap 则是随机分配内存,不定长度,存在内存分配和回收的问题;” Why?

这个问题需要测试一下。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值