什么是堆类型对象对象、类型

2023-09-03 03:01:47 作者:γ命中缺你γ

我知道,当物体在堆的创建,他们也有额外的两个字段:

I know that when objects are created in Heap, they also have extra two more fields:

同步块索引 类型的对象指针

所以我不知道,当类型对象在堆内存中创建并拥有什么样的数据?它仅重presents类型的元数据?

So I wonder when Type Object is created in Heap memory and what kind of data it holds? It only represents the metadata of the Type?

我一直没能找到太多的细节有关。

I haven't been able to find much detail about that.

推荐答案

该类型的对象还包含备份任何静态字段的类型,以及一个方法表,每个中的类型定义的方法一个条目的字节数。

The Type object also contains the bytes that back any static fields on the type as well as a method table with one entry per method defined within the type.

如果该方法已被执行至少一次的方法表指向JIT编译的原生code每个条目。

Each entry in the method table points to JIT-compiled native code if the method has been executed at least once.

类型对象被创建的第一次的类型实例化或第一次的静态型部件被引用。

The type object is created the first time the type is instantiated or the first time a static type member is referenced.

我强烈建议购买杰弗里里希特的书的副本, CLR通过C#如果你要得到一个什么样的CLR做了非常深的了解。标题为第4章在运行时如何事情相关的部分涵盖了详细堆中的.NET类型分配过程。

I highly recommend buying a copy of Jeffrey Richter's book, CLR via C# if you want to get a really deep understanding of what the CLR does. The section titled "How Things Relate at Runtime" in chapter 4 covers the .NET type allocation process on the heap in detail.

有一些很好的信息,以及这个MSDN杂志文章,专在类型基础和的方法表。

This MSDN Magazine article has some good information as well, specifically the sections on Type Fundamentals and MethodTable.