<p dir="ltr"><br>
On 06 Jan 2016 3:25 PM, "Minas Mina via Digitalmars-d-announce" <<a href="mailto:digitalmars-d-announce@puremagic.com">digitalmars-d-announce@puremagic.com</a>> wrote:<br>
><br>
> On Wednesday, 6 January 2016 at 12:19:45 UTC, Jacob Carlborg wrote:<br>
>><br>
>> On 2016-01-05 15:44, Minas Mina wrote:<br>
>><br>
>>> It won't, but to use it again you need to allocate a new one (If I'm not<br>
>>> mistaken).<br>
>><br>
>><br>
>> Not explicitly. I don't know if the runtime allocates a new one. This works:<br>
>><br>
>> void main()<br>
>> {<br>
>> auto foo = ["foo" : 1];<br>
>> foo = null;<br>
>> foo["bar"] = 2;<br>
>> assert(foo["bar"] == 2);<br>
>> }<br>
><br>
><br>
> I believe it does, check out this example:<br>
> import std.stdio;<br>
><br>
> class C<br>
> {<br>
> int[int] squares;<br>
> }<br>
><br>
> void main()<br>
> {<br>
> auto squares = [0 : 0, 1 : 1];<br>
><br>
> C c = new C();<br>
> c.squares = squares;<br>
><br>
> writeln(c.squares is squares); // true<br>
><br>
> squares = null;<br>
> squares[10] = 100;<br>
> writeln(c.squares is squares); // false<br>
> }<br>
><br>
> If the runtime used the same underlying memory, the second writeln() would print true, right?<br>
> So if I am correct, a new AA is allocated.<br>
Probably depends on the current implementation. If you are using an associative array you are going to be allocating at least a little.</p>
<p dir="ltr">If you used an associative array backed by two arrays you could allocate and reuse memory when null is assigned. It would also be able to keep its insertion order. </p>