[fpc-devel] Little feature teaser

Sven Barth pascaldragon at googlemail.com
Sat Aug 3 09:25:42 CEST 2013


Am 03.08.2013 05:24 schrieb "Dennis Poon" <dennis at avidsoft.com.hk>:
>
>
>>>> What about code size?
>>>>
>>>
>>>
>>> The code size for one unit is the same as if you had (in that example)
>>> declared a variant of "IsIn" for each "LongInt" and "String". So for
each
>>> "IsIn<T>" specialization with different types new code is generated if
it
>>> does not yet exist in that unit. This means that if you call
"IsIn<LongInt>"
>>> in different units you'll have a "IsIn<LongInt>" implementation in each
>>> unit. This is the same as for generic types btw.
>>>
>>> Regards,
>>> Sven
>>>
>>
>>
>> And the same (problem) in C++. Is there some proposal to mitigate the
>> code duplication? Or the official position is that if the project is
>> big enough to suffer from the bloat it should avoid itself the
>> duplicate declarations?
>>
>>
>>
>
> If we create a third unit with a wrapper function in which it specializes
the call, can we avoid the duplication code problem?

And what would you have won with that? The idea behind generics is that you
don't need to write a common piece of code multiple times for diffrent
types in the source, but that the compiler is handling that for you.
In your variant you'd need to call the wrapper instead of directly the
generic to keep the size small and if you call the wrapper multiple times
you'd trade performance (additional call) for size. Inlining might reduce
this a bit again though...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130803/d5701163/attachment.html>


More information about the fpc-devel mailing list