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

查看:20
本文介绍了.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?

我问的原因是我们试图估计相当大的数据语料库的几种不同的内存表示将占用多少内存,并且数组的大小差异很大,因此开销可能对一种解决方案产生很大影响,但对另一种解决方案可能影响不大.

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.

推荐答案

很好的问题.我发现 这篇 文章,其中包含值类型和引用类型的框图.另请参阅此文章 其中 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:

[snip] 每个数组都有一些额外的相关的开销信息它.此信息包含排名数组的(维数),每个维度的下限数组(几乎总是 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天全站免登陆