TObject包含什么数据? [英] What data does a TObject contain?
问题描述
TObject.InstanceSize返回8,但TObject不声明任何数据成员。根据TObject.ClassType的实现,前4个字节可以解释为指向对象的TClass元数据的指针。任何人都知道其他4个字节的开销是什么?
TObject.InstanceSize returns 8, yet TObject doesn't declare any data members. According to the implementation of TObject.ClassType, the first 4 bytes can be explained as a pointer to the object's TClass metadata. Anyone know what the other 4 bytes of overhead are there for?
编辑:显然这是D2009特有的。在旧版本中,只有4个字节。
Apparently this is specific to D2009. In older versions, it's only 4 bytes.
推荐答案
In Delphi 2009, there is the ability to have a reference to a synchronization monitor. See:
class function TMonitor.GetFieldAddress(AObject: TObject): PPMonitor;
class function TMonitor.GetMonitor(AObject: TObject): PMonitor;
...在System.pas中
...in System.pas
此外,还有一个指向VMT的指针。 (虚拟方法表。)从中的Delphi简介:
Also, there is still a pointer to the VMT. (Virtual Method Table.) From Delphi in a Nutshell:
TObject类声明了几个
方法和一个特殊的隐藏字段
来存储对对象的
类。这个隐藏的字段指向
类的虚拟方法表(VMT)。
每个类都有一个唯一的VMT,该类的所有
对象共享
类的VMT。
The TObject class declares several methods and one special, hidden field to store a reference to the object's class. This hidden field points to the class's virtual method table (VMT). Every class has a unique VMT and all objects of that class share the class's VMT.
这篇关于TObject包含什么数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!