不要值类型具有类型的对象?类型、对象

2023-09-05 04:12:55 作者:烟味少女

我相信,如果标题是explainatory与否,但我需要一些帮助理解的概念。

I am sure if the Title is explainatory or not, but I need some help understanding the concept.

我们拥有一流的(引用类型)与Type对象相关的方法表。 除了该方法的表,所述类型的对象还包含了所有的静态字段,类型物镜指针和同步块索引

We have class (reference types) that has method table associated with Type object. In addition to the method tables, the type object also contains all the static fields, type obj pointer and sync block index.

CLR将这种方法表调用引用类型的实例方法的时候。

CLR refers to this method table when calling methods on instance of a reference type.

方法表中包含的IL为用于改变实例字段的状态的特定的方法。

Method table contains the IL for a particular method that is used to change the state of instance fields.

同样,我们可以定义为一个结构的方法(值类型)。

Similarly we can define methods for a structs (value types).

在运行时,当一个方法被调用的值类型,从哪里CLR的参考方法的IL被称为上的值类型的实例。

struct A
{
    // for Immutability of value type
    public readonly int a;

    public void MethodOnValueType()
    {
        // Some code here
    }
}

哪里CLR指发现IL名为方法MethodOnValueType?

有任何类型的对象在托管堆中的值类型?

我相信,对于引用类型的案件,但困惑的值类型。

感谢。

推荐答案

在值类型的方法不支持多态(除了从对象继承的方法,这是执行的不同取决于他们是否已被覆盖):通话是一个静态调用(而不是虚拟呼叫)。基本上,呼叫信息是什么方法部分是由编译器解析,并烧入IL。它是那么JIT的作业,该呼叫连接到最后一个方法code。

Methods on value-types do not support polymorphism (except for the methods inherited from object, which are executed differently depending on whether they have been overridden): the call is a static call (not a virtual call). Basically, the "what method" part of the call information is resolved by the compiler and burned into the IL. It is then the job of the JIT to connect that call to the final method code.

有一个值类型没有对象头等等。

There is no object-header etc on a value-type.

您可以得到价值类型Type对象,但并没有真正涉及到的方法调用。

You can get a Type object for value-types, but that is not really related to method-call.

 
精彩推荐
图片推荐