堆栈和堆的含义是什么,它们之间有什么区别 [英] what is meant by stack and heap and what is the difference between them

查看:74
本文介绍了堆栈和堆的含义是什么,它们之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

堆栈和堆的含义是什么,它们之间的区别是什么?

what is meant by stack and heap and what is the difference between them

推荐答案

堆栈是特定于线程的内存区域,其值是每次输入方法时从顶部开始分配.
堆是不属于线程的内存的不同区域,可以根据需要从中分配值.

最大的区别是基于堆栈的值是临时的.当您离开创建它们的方法时,它们就消失了,再次尝试使用它们将导致严重的问题.堆值没有此限制.

堆栈值更快-分配要容易得多,因为您不必寻找空间,分配它并为使用做好准备-您只需转到变量=栈顶,栈顶+ =变量大小"因为在方法结束时将全部取消分配.堆无法做到这一点,它需要保留对什么位置的引用,以便可以正确删除它,并在以后重新使用该空间.

这是一个复杂的主题,但是Google和MSDN可以帮助您找到其他信息.
A stack is an area of memory that is thread specific and from which values are allocated from the top each time you enter a method.
A heap is a different area of memory that is not thread specific and from which values are allocated as needed.

The big difference is that stack based values are temporary. when you leave the method in which they were created, they are gone, and trying to use them again will cause massive problems. Heap values do not have this limitation.

Stack values are faster - allocation is much, much easier because you do not have to look for a space, allocate it, and prepare it for use - you just go "Variable = top of stack, top of stack += size of variable" because it will all be deallocated when the method ends. Heap can''t do that, it needs to keep references to what is where so it can be deleted properly and the space re-used later.

It''s a complex subject, but Google and MSDN can help you find other information.


请看 ^ ]


这篇关于堆栈和堆的含义是什么,它们之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆