8.2.13 Class types

Just like objects, classes are stored in memory just as ordinary records with an extra field: a pointer to the Virtual Method Table (VMT). This field is stored first, and all fields in the class are stored in the order they are declared.

Contrary to objects, all data fields of a class are always stored in heap memory.

The memory allocated looks as in table (8.6).


Table 8.6: Class memory layout (32/64-bit model)




Offset What
32-bit64-bit



+0 +0Pointer to VMT.
+4 +8Data. All fields in the order they’ve been declared.




The Virtual Method Table (VMT) of each class consists of several fields, which are used for runtime type information. The VMT layout is illustrated in table (8.7). The VMT is constructed by the compiler.


Table 8.7: Class Virtual Method Table memory layout (32/64-bit model)




Offset What
32-bit64-bit



+0 +0Size of object type data
+4 +8Minus the size of object type data. Enables determining of valid VMT pointers.
+8 +16Pointer to ancestor VMT, Nil if no ancestor available.
+12 +24Pointer to the class name (stored as a shortstring).
+16 +32Pointer to the dynamic method table (using message with integers).
+20 +40Pointer to the method definition table.
+24 +48Pointer to the field definition table.
+28 +56Pointer to type information table.
+32 +64Pointer to instance initialization table.
+36 +72Pointer to the auto table.
+40 +80Pointer to the interface table.
+44 +88Pointer to the dynamic method table (using message with strings).
+48 +96Pointer to the Destroy destructor.
+52 +104Pointer to the NewInstance method.
+56 +112Pointer to the FreeInstance method.
+60 +120Pointer to the SafeCallException method.
+64 +128Pointer to the DefaultHandler method.
+68 +136Pointer to the AfterConstruction method.
+72 +144Pointer to the BeforeDestruction method.
+76 +152Pointer to the DefaultHandlerStr method.
+80 +160Pointer to the Dispatch method.
+84 +168Pointer to the DispatchStr method.
+88 +176Pointer to the Equals method.
+92 +184Pointer to the GetHashCode method.
+96 +192Pointer to the ToString method.
+100 +200Pointers to other virtual methods.




See the file rtl/inc/objpash.inc for the most current VMT information.