Question about dynamic arrays and slices
Tobias Pankrath
tobias at pankrath.net
Thu Jan 30 02:50:40 PST 2014
> This prints:
>
> a[0] = 2
> b[0] = 1
>
> That is, "a" was resized to a point where it needed to
> reallocate its contents. "b" still holds a reference to the old
> data. When, after the for loop, I change a's data, b's data
> doesn't change.
>
> Is this expected behaviour?
That's how it is.
> How can I safely pass around a dynamic array without being
> afraid someone will keep an old copy of the data?
I don't understand your exact requirements. Do you want to make
sure that everyone sees the updates to the array, even after a
relocation?
More information about the Digitalmars-d-learn
mailing list