On Sunday, 28 July 2019 at 17:21:25 UTC, dmm wrote:
  test(str);

The array is passed by value here, so changes to its ptr and length will not be seen outside the function.

However, what goes *through* the pointer - which includes the contents and the capacity - will be seen. The runtime tries to minimize weird stuff by opting for making the capacity 0 if the array structure has been modified in a function (so of the length is changed, if it is appended, etc.), so then appends will not stomp over contents from two different locations. Since the memory pointed to is a shared resource it is conservative in not reusing it.

You can read a bit more about this here https://dlang.org/articles/d-array-article.html#append-on (really the whole article might be good background).

Reply via email to