TObject.InstanceSize返回8,但TObject没有声明任何数据成员.根据TObject.ClassType的实现,前4个字节可以解释为指向对象的TClass元数据的指针.任何人都知道其他4个字节的开销是什么?
编辑:显然这是D2009特有的.在旧版本中,它只有4个字节.
解决方法
在Delphi 2009中,有
the ability to have a reference to a synchronization monitor.请参阅:
class function TMonitor.GetFieldAddress(AObject: TObject): PPMonitor; class function TMonitor.GetMonitor(AObject: TObject): PMonitor;
…在System.pas中
此外,仍然有一个指向VMT的指针. (虚拟方法表.)From Delphi in a Nutshell:
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.