[fpc-pascal] Question about System.Move()
Sven Barth
pascaldragon at googlemail.com
Sun Jan 10 12:09:27 CET 2021
Am 09.01.2021 um 18:23 schrieb Bart via fpc-pascal:
> On Sat, Jan 9, 2021 at 5:12 PM Yuriy Sydorov via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>
>>> 2. Is it OK if the elements of the array are (or contain) managed types?
>> You need to manually finalize/free elements which are overwritten before calling Move.
> So, if I move Arr[3] to Arr[1], I first have to finilize/free Arr[1].
> After that move the bytes in Arr[3] are exactly the same as in Arr[1]
> (by definition of how move works) AFAIU.
> Is that a problem with refcounts, because they would be the same also
> but the number of copies increased?
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.
Regards,
Sven
More information about the fpc-pascal
mailing list