[fpc-devel] Newbie question: how does the compiler know the class type of an object ( the Is operator)
ewald at yellowcouch.org
Fri Aug 22 20:54:19 CEST 2014
On 08/22/2014 07:53 PM, Dennis Poon wrote:
> Howard Page-Clark wrote:
>> program Project1;
>> uses classes;
>> WriteLn('InstanceSize of TObject=',TObject.InstanceSize);
> I tried and it says the instancesize is 4 (on win 32 bit).
> My question actually was how does the "as" and "is" get the class type
> of an object.
> So, does that imply the 4 byte is used to store a pointer to the class
> type and Virtual Method table?
Have a look at the documentation concerning TObject.
It's the boilerplate of TObject that does the magic. (at least at
runtime, I don't know about compile time optimizations concerning the
`as` and `is` operators)
Also, to get a better idea of the size of a TObject in memory,
SizeOf(TVmt) will get you started?
More information about the fpc-devel