哪里是值类型存储在(C#)泛型集合 [英] Where Are Value Types Stored In (C#) Generic Collections

查看:106
本文介绍了哪里是值类型存储在(C#)泛型集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是事实,泛型集合的表现比非泛型集合值类型更好。 (即相对于表的ArrayList)。

It is true that generic collections perform better than non-generic collections for value types. (i.e. List vs. ArrayList).

但是,为什么是这样的,比装箱拆箱步其他?在哪里存储的值类型的对象,一旦添加到收藏?在非泛型集合,他们将被装箱,并存储在堆,什么是仿制药不同?

But why is that, other than the boxing-unboxing step? Where are the value type objects stored once added to the collection? In non-generic collections, they'll be boxed and stored on heap, what is different in generics?

推荐答案

在仿制药,如名单,其中,T> ,他们仍然保存在堆上。所不同的是,在内部,一列表与所述; INT> 使得整数的单一阵列,并且可以直接存储的数字。与ArrayList中,你最终存储引用数组盒装整数值。

In generics, such as List<T>, they're still stored on the heap. The difference is that, internally, a List<int> makes a single array of integers, and can store the numbers directly. WIth ArrayList, you end up storing an array of references to boxed integer values.

这篇关于哪里是值类型存储在(C#)泛型集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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