Can I see somehow an VMT table in FREE Pascal? I am interested if VMT table has the same number of items in two objects that are connected by heredity?
For example in this model, what will be in the VMT table ?
And will there be ONE table for all functions or more (table between [Ob1 AND Ob2] and table between [Ob2 AND Ob3] )?
What will be in the table(s)?
Ob1 = object
constructor Init;
function f1..; virtual;
function f2..; virtual;
end;
Ob2 = object(Ob1)
constructor Init;
function f1...; virtual;
function f2...; virtual;
function f3...; virtual;
end;
Ob3 = object(Ob2)
constructor Init;
function f1...; virtual;
function f2...; virtual;
function f3...; virtual;
end;
In runtime you can get a pointer to VMT of an object instance with TypeOf intrinsic (like this:
TypeOf(Obj)
). Internal structure of the returned VMT is documented in 8.2.12 Object types of the Free Pascal Programmer’s Guide.You can also dump VMTs while compilation. To do that compile your program with
-al
option ("List sourcecode lines in assembler file") and read lines in the generated.s
file related to the VMTs. For your example I got this on my PC (Win32 for i386
target):Here you can clearly see that virtual methods are started from fourth cells in the VMTs. First cell of an VMT is size of object, third is the pointer to parent's VMT. The
-4
s are negative sizes of objects and used for validating pointers to VMT.One VMT for each object type. There is no tables between objects, VMTs are attached to objects itself.