Member access of __gshared global object

Puming via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 30 19:03:35 PDT 2014


Hi,

I'm writing this global Config class, with an AA member:

```d
module my.config;

class Config
{
     Command[string] commands;
}

__gshared Config CONFIG;
```

and initialize it in another module:

```d
module my.app;

import my.config;

void main()
{
   CONFIG = new Config();
   CONFIG.commands["bye"] = new Command(...); // add commands
}
```

This is OK. But when I use a local variable to hold the commands 
AA:

```
auto cmds = CONFIG.commands;
cmds["list"] = new Command(...);
```

The command "list" is not added.

I guess what happened here was that `cmds` is a threadlocal 
variable, so the compiler somehow copied the CONFIG.commands.

My questions are:

1. Are AAs reference type? if so, why does the compiler copy it?
2. How do I reference a member of __gshared global objects?


More information about the Digitalmars-d-learn mailing list