How much information is copied / shared when I assign one array variable to another array variable?
int[] a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
int[] b = a;
a[0] = 42;
writefln("%s %s", a[0], b[0]); // 42 42
Apparently, athey buse the same payload, because 42 is printed twice.
a ~= 10;
writefln("%s %s", a.length, b.length); // 11 10
Adding in adoesn't change b, so length doesn't seem to be part of the payload?
b = a;
a ~= 11;
b ~= 42;
writefln("%s %s", a[11], b[11]); // 11 42
Is it possible that the corresponding implementation of D will also print 42 42? Failed to b ~= 42overwrite 11 inside a?
When exactly are separated aand beach other? Is D executing some COW in the background?
source
share