[fpc-pascal] How to avoid Copy
Michael Van Canneyt
michael at freepascal.org
Sun Dec 31 20:46:24 CET 2023
On Sun, 31 Dec 2023, Amir--- via fpc-pascal wrote:
>
>
> On 12/31/23 02:46, Marco van de Voort via fpc-pascal wrote:
>>
>> 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.
> Understand (and this is what I ended-up doing). I guess my question is
> that why we do not to have a PointerIterator in TList class.
Because no-one thought to implement it, or no-one saw the need.
Michael.
More information about the fpc-pascal
mailing list