[fpc-pascal] How to avoid Copy

Marco van de Voort fpc at pascalprogramming.org
Sun Dec 31 11:46:52 CET 2023


Op 31/12/2023 om 04:11 schreef Amir--- via fpc-pascal:
>
> I compiled the code with `fpc -O3 -Sd -gv -g -gl ` and ran `valgrind` 
> on it (the output is attached). It does not look like there is a big 
> difference between the Check1 and Check2 but Check3 is about 20 times 
> faster than the other two.
> I believe the issue could be resolved if we make 
> "TCustomListWithPointers.GetPtrEnumerator" a public method. Then, one 
> can implement the following function:
>
  I also do this (an enumerator using a pointer type) in one of my 
container types. It also makes assignment in the for in possible.  Note 
though that it is not necessarily needed to switch the whole collection 
to use a pointer, defining a separate iterator (e.g. 
collection.pointeriterator) that returns an iterator instantiated for 
^T.   You can then select the iterator by using for element in 
collection.iterator do.

The rtl-generics collections already have multiple iterators since for 
maps it is possible to iterate over the keys, the values or 
TPair<TKey,TValue)



More information about the fpc-pascal mailing list