[fpc-pascal] Generics vs templates

Sven Barth pascaldragon at googlemail.com
Tue Jan 9 08:04:06 CET 2018


Am 09.01.2018 02:59 schrieb "Ryan Joseph" <ryan at thealchemistguild.com>:



> On Jan 9, 2018, at 3:30 AM, Graeme Geldenhuys <
mailinglists at geldenhuys.co.uk> wrote:
>
> Recently I did a very simple test with Delphi XE3 using TList<Integer>
and a stock TList. Adding 50,000 and 200,000 integer values to each list,
and timing the creation of the list and population of the list. Then I also
timed the destruction of the list. I was horified to find out how much
slower Delphi's Generics were compared to TList and TObjectList.
Destruction was 250x slower in many cases. Creation and population of the
list was 5x-10x slower.

What does this have to do with generics exactly? If I understand correctly
generics are “meta-programming” where they essentially just re-insert a
generated class based on the template (c++’s naming scheme makes more sense
imo) but they don’t actually add any runtime code.


But you need to program in a way that allows the usage of multiple,
different types. That can more often than not lead to worse performance.

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


More information about the fpc-pascal mailing list