Push! to reshape-d vector unshares data with parent array

Docs only talks about “setting elements” which means an assignment operation if I understand things correctly.

(unless you mean that docs do not mention that by resizing the return value you unshare it - indeed it could be improved and this information could be added)

My understanding of this design decision is as follows:

  • x is informed (via flags.how) that y uses the same data as x owns, so x is not allowed to be resized, as it could corrupt y which reuses xs data.
  • However, reallocating y does not affect x. If you allocate a new memory for y you are sure that it will not corrupt x.

(of course the design also could be that y would be disallowed to be reallocated, but I assume that the developer of this functionality did not want to introduce such a restriction as it was not needed)

2 Likes