我试图了解存储在方法表中的信息。这是我的代码。
class MyClass
{
private int x = 60;
private int y = 90;
public void MethodB()
{
Console.WriteLine("MethodB");
}
public void MethodC()
{
Console.WriteLine("MethodC");
}
public void MethodA()
{
GetHashCode();
Monitor.Enter(this);
Console.WriteLine("Attach debugger now");
Console.ReadKey();
}
static void Main(string[] args)
{
MyClass mc = new MyClass();
mc.MethodA();
}
}
这是对象在内存中的样子
0:000> !do 0x02368a1c
Name: ConsoleApplication1.MyClass
MethodTable: 001f3310
EEClass: 001f136c
Size: 16(0x10) bytes
(C:\Download\PresentationPrep\TechDaysDemos\SomeTesting\bin\Debug\SomeTesting.exe)
Fields:
MT Field Offset Type VT Attr Value Name
6d032da0 4000001 4 System.Int32 1 instance 60 x
6d032da0 4000002 8 System.Int32 1 instance 90 y
然后我转储方法表
0:000> dd 001f3310
001f3310 00000000 00000010 00050011 00000004
001f3320 6d030770 001f2f2c 001f334c 001f136c
001f3330 00000000 00000000 6cf86ab0 6cf86ad0
001f3340 6cf86b40 6cff7540 008500d0 00000080
001f3350 00000000 00000000 00000000 00000000
001f3360 00000000 00000000 00000000 00000000
001f3370 00000000 00000000 00000000 00000000
001f3380 00000000 00000000 00000000 00000000
这是我发现有点混乱的地方。
第一个字段指示对象的类型(如果它是类或数组等)。我的理解是,对于类,此字段显示
0x00040000
,而此处仅显示0x00000000
.第二个字段是对象的大小。这个还行。
第三场有什么意义
00050011
?这个表示继承方法的数量,它指向父对象类的方法
ToString
、、Equals
和。这个对吗?GetHashCode
Finalize
我不了解其他领域,所以如果有人也解释一下,将不胜感激。