[fpc-pascal] For ..in GetEnumerator Allocation

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Wed Oct 4 13:21:18 CEST 2017

On 2017-10-04 09:41, Ryan Joseph wrote:
> I’d like to remove all these alloc/deallocs so I can use for..in more efficiently in tight loops.

I've had the same requirement, and also needed that functionality before 
the for..in syntax existed in FPC. Take a look at my Iterator interface 
and implementation. It allows you to move forward, backwards, reset, 
filter data etc. You can hold on to the instance reference as long as 
you like.

This code lives in the tiOPF project, but can be used outside of the 
tiOPF project too (I do that often) - simply delete the iterator 
implementations for TtiObjectList.



Some years ago I wrote a article for a magazine about this, and that is 
when I implemented the code. You can still find the "Iterator" article 
in the link below - and the accompanied source code too (though the 
tiOPF code is newer).



fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal

My public PGP key:  http://tinyurl.com/graeme-pgp

More information about the fpc-pascal mailing list