[fpc-pascal] Dynamic arrays, yet another pitfall

Martin Frb lazarus at mfriebe.de
Mon Feb 17 20:41:57 CET 2014


On 17/02/2014 19:34, Marco van de Voort wrote:
> In our previous episode, Martin Frb said:
>> Just because there is a function, that includes copying (when modifying
>> the array), does not mean there is copy on write.
> So basically, if for a given size x, setlength(x,1) always reallocates, then
> it is COW, otherwise not :-)
Not sure what you mean?

>
> (and even if it does, one could still argue it is an implementation detail)
>

But if you want to use the term, IMHO it would be:
"Dynamic arrays have no copy-on-write. But SetLength perform a 
copy-on-write on dynamic arrays."

I am not sure, if that makes to much sense either. copy-on-write should 
apply to the data type, not to the/a function that acts on data of that 
type.

And the data type "dyn array" does not have copy-on-write.
If it had, the *ALL* [1] write operation would have to trigger the COW.

[1] this excludes access via pointer, that is designed to bypass the 
type specific behaviour.




More information about the fpc-pascal mailing list