[fpc-devel] Newbie question: how does the compiler know the class type of an object ( the Is operator)

Dennis Poon dennis at avidsoft.com.hk
Sat Aug 23 11:34:52 CEST 2014


> http://www.freepascal.org/docs-html/prog/progsu168.html#x212-2250008.2.13
>
> Table 8.6 is the class instance memory layout and 8.7 is the class vmt
> which has info on it's name and ancestor classes.
Andrew,

the page says:


        8.2.13 Class types
        <http://www.freepascal.org/docs-html/prog/prog.html#QQ2-212-239>

Just like objects, classes are stored....

Look like it is referring to a TClass instance instead of an TObject 
instance but thanks  a lot for pointing me into the right direction.

My second newbie question is, in modern day CPUs and fpc compiler, are 
optimized code generated for fpc program to cleverly use the available 
registers and instructions to look up method address of an object when 
the method is called, so that Object oriented language code can now run 
as fast as procedural languages?

I don't know assembly so cannot tell from the asm generated for the 
sample program:
# [18] t := TTest.Create;
         movl    $VMT_TVMTPTR_TTEST,%edx
         movl    $0,%eax
         call    SYSTEM_TOBJECT_$__CREATE$$TOBJECT
         movl    %eax,U_TVMTPTR_T

With modern CPU, can the above 4 lines be further optimized?

Dennis
> Regards,
>
> Andrew Haines
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2014.0.4745 / Virus Database: 4007/8083 - Release Date: 08/22/14
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140823/0c8137bd/attachment.html>


More information about the fpc-devel mailing list