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.9).
Offset | What | |
32-bit | 64-bit | |
+0 | +0 | Pointer to VMT. |
+4 | +8 | 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.10). The VMT is constructed by the compiler.
Offset | What | |
32-bit | 64-bit | |
+0 | +0 | Size of object type data |
+4 | +8 | Minus the size of object type data. Enables determining of valid VMT pointers. |
+8 | +16 | Pointer to ancestor VMT, Nil if no ancestor available. |
+12 | +24 | Pointer to the class name (stored as a shortstring). |
+16 | +32 | Pointer to the dynamic method table (using message with integers). |
+20 | +40 | Pointer to the method definition table. |
+24 | +48 | Pointer to the field definition table. |
+28 | +56 | Pointer to type information table. |
+32 | +64 | Pointer to instance initialization table. |
+36 | +72 | Pointer to the auto table. |
+40 | +80 | Pointer to the interface table. |
+44 | +88 | Pointer to the dynamic method table (using message with strings). |
+48 | +96 | Pointer to the Destroy destructor. |
+52 | +104 | Pointer to the NewInstance method. |
+56 | +112 | Pointer to the FreeInstance method. |
+60 | +120 | Pointer to the SafeCallException method. |
+64 | +128 | Pointer to the DefaultHandler method. |
+68 | +136 | Pointer to the AfterConstruction method. |
+72 | +144 | Pointer to the BeforeDestruction method. |
+76 | +152 | Pointer to the DefaultHandlerStr method. |
+80 | +160 | Pointer to the Dispatch method. |
+84 | +168 | Pointer to the DispatchStr method. |
+88 | +176 | Pointer to the Equals method. |
+92 | +184 | Pointer to the GetHashCode method. |
+96 | +192 | Pointer to the ToString method. |
+100 | +200 | Pointers to other virtual methods. |
… | ||
See the file rtl/inc/objpash.inc for the most current VMT information.