AA with dynamic array value

Craig Dillabaugh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 5 20:24:28 PDT 2016


On Wednesday, 6 July 2016 at 02:33:02 UTC, ketmar wrote:
> On Wednesday, 6 July 2016 at 02:19:47 UTC, Craig Dillabaugh 
> wrote:
>> [...]
>
> this is true for any dynamic array, including AAs. until 
> something is added to array, it actually a `null` pointer. i.e. 
> arrays (and AAs) generally consisting of pointer to data and 
> some length/info field. while array is empty, pointer to data 
> is `null`. and when you passing your dynamic array slice/AA to 
> function, it makes a copy of those internal fields. reallocing 
> `null` doesn't affect the original variable.
>
> generally speaking, you should use `ref` if you plan to make 
> your dynamic array/AA grow. i.e.
>
>  void insertValue (ref int[][string]aa, string key, int value)

Thanks for giving me the correct solution, and for the 
explanation.

Cheers,
Craig


More information about the Digitalmars-d-learn mailing list