Difference between revisions of "Compiler-generated data and data structures"
From Free Pascal wiki
Jump to navigationJump to searchLine 8: | Line 8: | ||
The layout of the VMT generated by FPC (Aug. 2006) is shown in the following table. | The layout of the VMT generated by FPC (Aug. 2006) is shown in the following table. | ||
{| | {| | ||
− | |+ entry offset | + | |+ entry |
+ | | offset | ||
| explanation | | explanation | ||
|- | |- | ||
| vmtInstanceSize | | vmtInstanceSize | ||
| 0 | | 0 | ||
+ | | | ||
|- | |- | ||
| vmtParent | | vmtParent | ||
| sizeof(ptrint)*2; | | sizeof(ptrint)*2; | ||
+ | | | ||
|- | |- | ||
|} | |} |
Revision as of 23:11, 5 August 2006
Introduction
The compiler generates several data when compiling a program, this article describes its layout.
Classes layout
One of the most important data in an object pascal program are classes. A class is a pointer to the actucal data of a given instance. The first entry in the data of an object is a pointer to its virtual method table (VMT). This name is historic because this table contains nowadays more information than only the pointers to the virtual methods. It contains information about the
VMT layout
The layout of the VMT generated by FPC (Aug. 2006) is shown in the following table.
offset | explanation | |
vmtInstanceSize | 0 | |
vmtParent | sizeof(ptrint)*2; |
vmtClassName = vmtParent+sizeof(pointer);
|-
vmtDynamicTable = vmtParent+sizeof(pointer)*2;
|-
vmtMethodTable = vmtParent+sizeof(pointer)*3;
|-
vmtFieldTable = vmtParent+sizeof(pointer)*4;
|-
vmtTypeInfo = vmtParent+sizeof(pointer)*5;
|-
vmtInitTable = vmtParent+sizeof(pointer)*6;
|-
vmtAutoTable = vmtParent+sizeof(pointer)*7;
|-
vmtIntfTable = vmtParent+sizeof(pointer)*8;
|-
vmtMsgStrPtr = vmtParent+sizeof(pointer)*9;
|-
{ methods } vmtMethodStart = vmtParent+sizeof(pointer)*10;
|-
vmtDestroy = vmtMethodStart;
|-
vmtNewInstance = vmtMethodStart+sizeof(pointer);
|-
vmtFreeInstance = vmtMethodStart+sizeof(pointer)*2;
|-
vmtSafeCallException = vmtMethodStart+sizeof(pointer)*3;
|-
vmtDefaultHandler = vmtMethodStart+sizeof(pointer)*4;
|-
vmtAfterConstruction = vmtMethodStart+sizeof(pointer)*5;
|-
vmtBeforeDestruction = vmtMethodStart+sizeof(pointer)*6;
|-
vmtDefaultHandlerStr = vmtMethodStart+sizeof(pointer)*7;