English 中文(简体)
阵列对阵列列表的重大差异? [重复]
原标题:Significant differences in Array vs Array List? [duplicate]
This question already has answers here:
Closed 12 years ago.

Possible Duplicate:
When to use ArrayList over array[] in c#?

从内存或处理器成本的角度来看,一个阵列和一个阵列对象之间似乎有显著差别吗?

问题回答

数组是一个低层次的数据结构,基本上映射到内存的区域。 ArrayList 是一个变量长度列表,它作为“code>object ”的数组执行,随着列表的增长被重新配置。

因此,ArrayList 有一些间接费用与内部阵列的大小管理有关,更多的间接费用与进入清单时将物体投入正确类型的有关。

此外,将所有内容作为 object 存储,意味着价值类型被框在书写上,而没有框在阅读上,这对性能极为有害。使用 List<T>,一个类似但非常强烈的变量大小列表可以避免这一问题。

事实上,ArrayList 实际上被贬低为 List<T> ,自.NET 2. 0以来。

数组是固定大小的内存的毗连区块,而矩阵列表员(尽管您更喜欢列表,因为.NET 2. 0) 则将数组包起来,以提供动态可变存储。

两者之间的“差异”在于,只要它们重新封装,一个阵列是可变的,一个阵列不是。就执行而言:因为一个阵列包(和重新分配)阵列需要比一个阵列多一点的内存(因为它必须知道目前的元素数量,而不是其容量),此外,一个阵列还要求CPU在达到内部能力时有时间重新分配和复制其内部阵列。

然而,即时处理一个阵列并不比分配阵列更昂贵。 唯一的区别在于启动阵列状态需要为数不多的指示。 区别微乎其微,不值得担心。

你会发现,如果你自己重新定位一个阵列作为创建可变缩放收藏的手段,那么你最好使用矩阵列表/列表,因为它已经经过彻底测试。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签