堆栈和堆 [英] stack and a heap

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

问题描述

堆和堆栈之间有什么区别?

what is the difference between a heap and a stack?

推荐答案

它们都是用于存储对象的内存。默认情况下堆栈

只存储像Struct和Integers这样的值类型,而堆使用

来为引用类型分配内存。


网上有很多关于此的文章。尝试谷歌搜索。

-

特里伯恩斯
http://TrainingOn.net


" shine" < SH *** @ discussions.microsoft.com>在消息中写道

新闻:5D ********************************** @ microsof t.com ...
They are both memory which is used to store objects. The stack by default
only stores Value types like Struct and Integers, whereas the Heap is used
to allocate memory for reference types.

There are numerous articles on the net about this. Try googling.
--
Terry Burns
http://TrainingOn.net

"shine" <sh***@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
堆和堆栈有什么区别?



Terry Burns< he * *@now.com>写道:
Terry Burns <he**@now.com> wrote:
它们都是用于存储对象的内存。默认情况下,堆栈只存储像Struct和Integers这样的值类型,而堆使用
为引用类型分配内存。
They are both memory which is used to store objects. The stack by default
only stores Value types like Struct and Integers, whereas the Heap is used
to allocate memory for reference types.




那个不幸的是,过于简单化了。堆栈还用于
存储引用(而不是对象本身),并且所有类型

都可以作为其他对象的一部分在堆上结束。


请参阅 http:// www .pobox.com / ~siget / csharp / memory.html


请注意,这并不能解释堆与
$ b之间的区别$ b stack,就在那里。


-

Jon Skeet - < sk *** @ pobox.com>
< a rel =nofollowhref =http://www.pobox.com/~skeettarget =_ blank> http://www.pobox.com/~skeet

如果回复该团体,请不要给我发邮件



That''s an oversimplification, unfortunately. The stack is also used to
store references (rather than the objects themselves), and all types
can end up on the heap as part of other objects.

See http://www.pobox.com/~skeet/csharp/memory.html

Note that this doesn''t explain the difference between the heap and the
stack, just what goes where.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




" shine" < SH *** @ discussions.microsoft.com>在消息中写道

新闻:5D ********************************** @ microsof t.com ...

"shine" <sh***@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
堆和堆栈有什么区别?




堆栈是一块进程内存,那'用于存储本地

变量,函数返回地址,指向下一个堆栈帧的指针和

之类的东西。堆栈从不保存引用类型的实例,当

局部变量引用引用类型时,变量的值

保存对GC堆分配对象的引用例如,当一个

局部变量引用一个值类型时,那么该类型的值就存储了与该变量内联的
。进程中的每个线程都有自己的私有

堆栈空间,在创建线程时分配固定的最大大小

(默认为1MB)。

AStackOverflow只要堆栈满了就会抛出异常。

堆是进程内存块,由执行程序的执行程序创建/管理

请求码。托管堆或GC堆只是

另一个堆由操作系统根据CLR的请求创建/管理。

GC堆是私有存储由CLR管理,仅用于存储

托管对象(引用类型实例或盒装值类型)。 GC堆的

大小是可变的,并且仅受进程中可用虚拟地址空间量的限制。 MemoryOverflow是指MemoryOverflow。每当可用的虚拟地址空间耗尽时,就会被抛出




Willy。



A stack is a chunk of process memory, that''s being used to store local
variables, function return addresses, pointers to next stack frame and
things like that. The stack never holds instances of reference types, when a
local variable refers to a reference type, then the value of the variable
holds a reference to a GC heap allocated object instance, however, when a
local variable refers to a value type, then the value of the type is stored
inline with that variable. Each thread in the process has his own private
stack space, allocated at thread creation time with a fixed maximum size
(default 1MB).
A "StackOverflow" exception will get thrown whenever the stack gets full.
A heap is chunk of process memory that''s being created/managed by the OS on
request of the executing program code. The managed heap or GC heap is just
another heap that''s being created/managed by the OS on request of the CLR.
The GC heap is a private store managed by the CLR and only used to store
managed objects (instances of reference types or boxed value types). The
size of the GC heap is variable, and is only restricted by the amount of
free virtual address space in the process. A "MemoryOverflow" gets thrown
whenever the available virtual address space is exhausted.

Willy.


这篇关于堆栈和堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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