This describes the semantics of regular arrays. Are you sure it also applies to AAs? I thought they will keep referring to the same data once they are initialized. But I might be mistaken...


This can be easily tested. And... you are right!

In the current implementation (I couldn't find any specification) the AA contains just a pointer[1]. I suppose that initially this pointer is null and on copy the pointer is copied, so that after initialization any change of the copy is visible in the original.

[1] https://github.com/D-Programming-Language/druntime/blob/master/src/rt/aaA.d#L82-85

Reply via email to