内存分配在.NET集合 [英] Memory allocation for collections in .NET

查看:92
本文介绍了内存分配在.NET集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个傻瓜。我没有找到这个足够的信息。

This might be a dupe. I did not find enough information on this.

我正在讨论的内存分配在.net集合。 哪里是为元素分配的内存中的集合?

I was discussing memory allocation for collections in .Net. Where is the memory for elements allocated in a collection?

List<int> myList = new List<int>();

变量myList中被分配在栈,它引用在堆上创建的列表对象。

The variable myList is allocated on stack and it references the List object created on heap.

的问题是当INT元素被添加到该myList中,在那里将被创建他们?

The question is when int elements are added to the myList, where would they be created ?

任何人都可以指向正确的方向?

Can anyone point the right direction?

推荐答案

元素也将驻留在堆(在数组中,这就是列表的内部工作原理)。

The elements will also reside in the heap (in an array, that's how List works internally).

在原则上,只有局部变量和参数都被分配在堆栈上和其他一切那张堆(除非你用罕见的东西,如 stackalloc ,但你不吨需要担心)

In principle, only local variables and arguments are be allocated on the stack and everything else goes on the heap (unless you use rare things such as stackalloc, but you don't need to worry about that)

这篇关于内存分配在.NET集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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