Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Artifact ID: | 099a0f380b34a14b725ee5e29572fb996cfa7b260fdd58e43697b056a5f77b29 |
---|---|
Page Name: | are AA value pointers invalidated by AA mutation? |
Date: | 2021-10-30 11:27:34 |
Original User: | admin |
Content
Are AA value pointers invalidated by AA mutation?
In other words, does this program run without error?
void main() { int[int] aa = [1: 2]; int* p = 1 in aa; foreach (i; 3 .. 10_000_000) aa[i] = i; assert(aa.length == 10_000_000 - 2); assert(aa[1] == 2); assert(p == (1 in aa)); }
There's no error, despite it reallocating the AA after the pointer is taken, because the pointer is to an individually allocated bucket, rather than a pointer into the resized backing array.