[fpc-devel] Optimization for TObject.InheritsFrom (and the 'is' operator)

Peter Vreman peter at freepascal.org
Sat Jul 21 16:53:24 CEST 2007


>
> On 21 Jul 2007, at 15:06, Jonas Maebe wrote:
>
>>>  InheritsFrom := (AClass <= Self) and (Self < PClass(pointer
>>> (AClass) + vmtNextSibling)^);
>>>
>>> (In this implementation vmtNextSibling should not be nil for those
>>> classes that have no NextSibling in the hierarchy, but have a
>>> value larger than all vmts. An alternative is to have an
>>> vmtLastChild, which is always properly defined; it points to the
>>> last one of: itself, its children, its grandchildren, etc.)
>>
>> I don't think this can work, since a class hierarchy is a tree and
>> not a list. So in case of
>>
>> TObject
>> |
>> +-- TA
>> |
>> +-- TB
>>
>> How would you linearise that in memory? As TObject - TA - TB ?
>>
>> In that case, TB inherirtsFrom TA would be (afaics)
>>
>> (TA <= TB) and (TB < TA+(inf))
>
> Sorry, no, this would be (TA <= TB) and (TB < TB), so it would be ok.
> Still, I don't think laying out classes in memory like this is easy
> to do without complex linker scripts (which are not supported on all
> platforms).

There is no garauntee either within a single unit. With forward defined classes you can make any
order you want.

And relying on order in memory has also problems with shared libraries. afaik there is no rule
that new libaries are always loaded at larger adresses

Peter





More information about the fpc-devel mailing list