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-bit model)



OffsetWhat


+0 Pointer to VMT.
+4 Data. 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-bit model)



OffsetWhat


+0 Size of object type data
+4 Minus the size of object type data. Enables determining of valid VMT pointers.
+8 Pointer to ancestor VMT, Nil if no ancestor available.
+12 Pointer to the class name (stored as a shortstring).
+16 Pointer to the dynamic method table (using message with integers).
+20 Pointer to the method definition table.
+24 Pointer to the field definition table.
+28 Pointer to type information table.
+32 Pointer to instance initialization table.
+36 Reserved.
+40 Pointer to the interface table.
+44 Pointer to the dynamic method table (using message with strings).
+48 Pointer to the Destroy destructor.
+52 Pointer to the NewInstance method.
+56 Pointer to the FreeInstance method.
+60 Pointer to the SafeCallException method.
+64 Pointer to the DefaultHandler method.
+68 Pointer to the AfterConstruction method.
+72 Pointer to the BeforeDestruction method.
+76 Pointer to the DefaultHandlerStr method.
+80 Pointers to other virtual methods.