Am 03.08.2013 05:24 schrieb "Dennis Poon" <den...@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
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to