一个.NET数组的内存布局 [英] Memory layout of a .NET array

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

问题描述

什么是.NET数组的内存布局?

What is the memory layout of a .NET array?

就拿这个数组:

Int32[] x = new Int32[10];

据我所知,大部分的数组是这样的:

I understand that the bulk of the array is like this:

0000111122223333444455556666777788889999

每个字符是一个字节,而数字对应的索引到数组。

Where each character is one byte, and the digits corresponds to indices into the array.

此外,我知道有一种类型的参考,和一个同步块指数对于所有的对象,因此,上述可调节到这样的:

Additionally, I know that there is a type reference, and a syncblock-index for all objects, so the above can be adjusted to this:

ttttssss0000111122223333444455556666777788889999
        ^
        +- object reference points here

此外,需要数组的长度来进行存储,所以,这可能是更正确的:

Additionally, the length of the array needs to be stored, so perhaps this is more correct:

ttttssssllll0000111122223333444455556666777788889999
        ^
        +- object reference points here

这是完整的?是否有更多的数据在一个阵列?

Is this complete? Are there more data in an array?

我问的原因是,我们试图估计多少内存一对夫妇一个相当大的数据语料库不同的内存重新presentations将采取和数组的大小而变化颇有几分,所以开销可能具有在一个解决方案有很大的影响,但也许不是那么在其他多

The reason I'm asking is that we're trying to estimate how much memory a couple of different in-memory representations of a rather large data corpus will take and the size of the arrays varies quite a bit, so the overhead might have a large impact in one solution, but perhaps not so much in the other.

因此​​,基本上,对于一个数组,多少开销是存在的,这基本上是我的问题。

So basically, for an array, how much overhead is there, that is basically my question.

和之前的数组不好的小队被唤醒,这种解决方案的一部分是静态集结一次基准往往事情的类型,以便使用可扩展的名单是没有必要在这里。

And before the arrays are bad squad wakes up, this part of the solution is a static build-once-reference-often type of thing so using growable lists is not necessary here.

推荐答案

大问题。我发现<一href="http://www.$c$cproject.com/KB/cs/net_type_internals.aspx?fid=459323&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2567811">this本文包含框图为值类型和引用类型。另请参阅此文章其中Ritcher规定:

Great question. I found this article which contains block diagrams for both value types and reference types. Also see this article in which Ritcher states:

[剪断]每个阵列有一些额外的   与相关的开销信息   它。此信息包含军衔   阵列的(维数),   对于每个维度的下限   阵列(几乎总是0),以及   长度每个维度的。开销   也包含各元素的类型   在该阵列

[snip] each array has some additional overhead information associated with it. This information contains the rank of the array (number of dimensions), the lower bounds for each dimension of the array (almost always 0), and the length of each dimension. The overhead also contains the type of each element in the array.

这篇关于一个.NET数组的内存布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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