delphiobjectdelphi-2009tobject

What data does a TObject contain?


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?

EDIT: Apparently this is specific to D2009. In older versions, it's only 4 bytes.


Solution

  • 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;
    

    ...in System.pas

    Also, there is still a pointer to the VMT. (Virtual Method Table.) 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.