Member access of __gshared global object
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 6 08:42:04 PDT 2014
On Wednesday, 6 August 2014 at 15:18:15 UTC, Dragos Carp wrote:
> On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote:
>>
>> This would defeat the purpose, see the original post.
>
> sorry, I red just the last post.
>
> __gshared has no influence on this.
Indeed, it was just what the OP suspected as the culprit.
>
>> auto cmds = CONFIG.commands;
>> cmds["list"] = new Command(...);
>
> cmds is a thread local variable referencing the shared AA. But
> if you add new elements to cmds, cmd will be reallocated and
> the shared AA will remain unchanged. Though, updated values of
> existing keys will be visible in the original, because no
> relocation takes place.
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...
>
> If you want to change the original you need a pointer or a
> reference (for a setter function).
>
> auto cmds = &CONFIG.commands;
> (*cmds)["list"] = new Command(...);
More information about the Digitalmars-d-learn
mailing list