Array slices and copy on write
simendsjo
simen.endsjo at pandavre.com
Sun Apr 3 05:29:47 PDT 2011
D will copy the original content if a slice expands, but is the following behavior
implementation specific, or part of the specification?
auto a = [0,1,2];
auto b = a[0..2];
a.length = 2; // is a[3] already marked for collection by the gc?
assert(a.ptr == b.ptr);
b.length += 1; // as b cannot reuse it even though noone is using it
assert(a.ptr == b.ptr); // ooops, fails.. b is reallocated
More information about the Digitalmars-d-learn
mailing list