[fpc-pascal] Dynamic arrays, yet another pitfall
Michael Van Canneyt
michael at freepascal.org
Mon Feb 10 09:13:27 CET 2014
On Sun, 9 Feb 2014, Florian Klämpfl wrote:
> Am 09.02.2014 18:41, schrieb Jürgen Hestermann:
>> So it seems there is a copy-on-write *but* only when using SetLength.
>
> No. There is no COW, only ref. counting. SetLength just forces an unique
> instance of the array if needed.
The documentation explicitly mentions that:
'Dynamic arrays are reference counted: assignment of one dynamic array-type
variable to another will let both variables point to the same array.
Contrary to ansistrings, an assignment to an element of one array will
be reflected in the other: there is no copy-on-write.'
But I have added a paragraph about the "reset ref. count" behaviour of setlength.
Michael.
More information about the fpc-pascal
mailing list