Am 2014-02-16 13:20, schrieb Michael Van Canneyt:
> Depends on how you define 'write to the array'.
> "Writing to the array" = "Changing the value of one of the elements in the 
array."
> In this sense, setlength does not write to the array, which would mean 
changing the value of
> one or more of the elements in the array. It does not do that. It resizes the 
array and
> the result is by definition a different array.

But what else than writing is it to add or remove elements?
It's definitely not reading.
Changing the length of an ansistring is writing too IMO.


> But taking the above definition, with "element" = "character", you see that 
ansistrings do have copy-on-write.

Nobody doubt that.
But dynamic arrays claim to *not* have copy-on-write although SetLength *does* 
a copy-on-write.
When comparing ansistrings to dynamic arrays:
Setlength on ansistrings does copy-on-write but the documentation says that 
copy-on-write does not exist for dynamic arrays.
Still Setlength on dynamic arrays does a copy-on-write in the same way as it 
does for ansistrings.


> It's largely a question of semantics, I suppose.

Well, IMO "writing" is doing changes to the stored data.
In opposite to reading it writes bytes to memory.
Reading the variable before and after a SetLength show different results 
(length() reports different values).

If Setlength should *not* be considered "writing" then the documenation needs 
to make this very clear.
It should not leave any doubts nor allow different interpretation of the 
behaviour.
Especially when such illogical and schizophrenic behaviour exists.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to