[fpc-pascal] Dynamic arrays, yet another pitfall

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


On 17/02/2014 19:50, Jonas Maebe wrote:
> On 17 Feb 2014, at 20:41, Martin Frb wrote:
>
>> "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
> It doesn't, because even if you don't change the length it makes a unique copy.
>

Right of course, it is an unconditional copy always (if refcount > 1). 
(same as unique instance)

But even **assuming** the following:
- setlength (with no length) to be considered a write
- copy only if length changes

That would still not mean that dyn array would have COW.
Because this would still be only one function acting on this type, where 
as other write operations on the type clearly show that: The data type 
dyn array has no COW





More information about the fpc-pascal mailing list