[fpc-pascal] Question about System.Move()

Bart bartjunk64 at gmail.com
Mon Jan 11 19:23:19 CET 2021


On Sun, Jan 10, 2021 at 12:09 PM Sven Barth via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

> If after the Move only one of the two references is reachable anymore
> (because e.g. some internal count variable "ends" the array before that
> element) then you don't need to care about increasing the reference
> count, cause there is only one reference after all (in that case you
> must *not* use an assignment to clear the value, but e.g. FillChar,
> cause the reference count must not be touched). Only if you'd really
> duplicate the element you'd need to take care of that.
>

OK, thanks for that.
I'll have to get my head around all the caveats.

Why did I ask in the first place?
Because I was doing some work on TDeque implementation (fixing a
simple range check error in TDeque.IncreaseCapacity).
Inside that procedure simple loop approach is used and I thought I
could maybe improve that, because when we increase capacity by less
than a factor 2, you cannot simply move data in one go and speed
difference (with moving data > 256 MB) might be significant.

I then contemplated all the above issues (I don't want to break
current implementation), but as far as I understand things TDeque
cannot be safely used with managed types as it is now. There is more
code that would need to finalize elements (PopBack, PopFront, Insert,
Clear) and certainly it does not support Objects (classes).
Which is fine, as long as you know it.

We could try to extend it, but now we have Generics.Collections etc:
do we already have a better generic Deque (double ended queue)
implementation somewhere?




-- 
Bart


More information about the fpc-pascal mailing list