Stupid question about AA. The following code works but I don't undrstand why?!
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 9 11:27:11 PDT 2016
On Saturday, 9 April 2016 at 18:06:52 UTC, Uranuz wrote:
> Thanks. It's clear now. AA holds not `array struct` itself
> inside, but pointer to it.
How the array is stored in the AA doesn't matter, as far as I can
see. The point is that you obtain a pointer to the array struct
in the AA, not a copy.
If you had tried it like the following, mapElem would be a copy
of the array struct in the AA, and the append would not affect
mapka["item"]:
----
string[] mapElem = "item" in mapka ? mapka["item"] :
(mapka["item"] = []);
mapElem ~= ["dog", "cat", "horse", "penguin", "fish", "frog"];
----
> So reallocation affects ptr to allocated memory but not pointer
> to `array struct`. I think that's it.
Correct.
More information about the Digitalmars-d-learn
mailing list