[fpc-devel] Generics.Collections as package for Lazarus or package for FPC RTL

Marco van de Voort marcov at stack.nl
Fri Jan 29 13:47:00 CET 2016

In our previous episode, Marcos Douglas said:
> > returning interfaces in a tight loop (e.g. to get the elements of an
> > enumeration) would be a new allocation each time.
> But even if you have small objects (max 3-5 methods and few attributes...) this
> overhead that you talk about be slow, is still considerable?

That overhead is not really dependent on the size of the object.
> In other words, do you consider refcounting always slow in all cases?

No. Only for the most inner loops. But general container types should not
have such limitations IMHO, which is why I use records in my container lib.

I don't see a reason for an iterator to be an interface anyway, since the
usage should be fairly local.

A typical example where it might happen is in a collection of collections
like a hash.  You have a couple of buckets and needs a type for the bucket
itself for the disambiguation.  Those are fairly small collections in a good
hash (since divided by hashsize), but there are lot of them (hashsize). Many
of them will only contain one item.

Iterating over all elements then creates and destroys hashsize iterators

More information about the fpc-devel mailing list