[fpc-pascal] Dynamic arrays, yet another pitfall

Marco van de Voort marcov at stack.nl
Mon Feb 17 21:49:33 CET 2014


In our previous episode, Martin Frb said:
> >> 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 :-)

That came out wrong wrong. Should've been for given x, setlength(p,x+1);  p (after) is
always not equal to p(before).

> Not sure what you mean?

I meant to say that if the implementation can increase the dyn array with 1
without reallocation, and it does nevertheless, it is COW not mere
reallocation.  

But since when to reallocate is implementation dependent, that is a hard
thing to prove.

> > (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."

... depending on allocation, Setlength might reallocate and copy ...




More information about the fpc-pascal mailing list