Re: Member access of __gshared global object

2014-08-07 Thread Puming via Digitalmars-d-learn
Indeed it's confusing. So AA is a value type that behaves like a pointer/reference. We can add a rule to the initialization to make AA behave more like reference types: If someone `refer` to an unitialized AA, that is, by doing: ```d string[string] aa; string[string] bb = aa; // bb

Re: Member access of __gshared global object

2014-08-07 Thread Kagamin via Digitalmars-d-learn
It's an optimization of memory allocation: you can always have a usable AA without allocating anything for it, so when you fill it with data, you may want to assign it back to where it should stay, similar to a slice.

Re: Member access of __gshared global object

2014-08-07 Thread Puming via Digitalmars-d-learn
Yes indeed, null initial value is reasonable. My suggestion does not affect that rationale, but is only based on my observation that if someone want to `refer` to an AA, he is more likely to fill it very soon, and he really mean to refer to it. These are similar concerns: - create a null AA,

Re: Member access of __gshared global object

2014-08-06 Thread via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote: On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference

Re: Member access of __gshared global object

2014-08-06 Thread hane via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote: 1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? workaround: string[string] aa; assert(aa is null); aa[] = ; aa.remove(); assert(aa !is null);

Re: Member access of __gshared global object

2014-08-06 Thread Dragos Carp via Digitalmars-d-learn
1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? Like arrays, associative arrays have value semantics. This means that they can be always referenced. It is easier to see this with an array: int[] a1 = null;

Re: Member access of __gshared global object

2014-08-06 Thread via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 14:22:32 UTC, Dragos Carp wrote: 1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? --snip-- This means if you want an empty AA you can write aa1 = null; or more explicit aa1 =

Re: Member access of __gshared global object

2014-08-06 Thread Dragos Carp via Digitalmars-d-learn
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. auto cmds = CONFIG.commands; cmds[list] = new Command(...); cmds is a thread local variable

Re: Member access of __gshared global object

2014-08-06 Thread via Digitalmars-d-learn
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

Re: Member access of __gshared global object

2014-08-06 Thread Dragos Carp via Digitalmars-d-learn
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... This can be easily tested. And... you are right! In the current implementation (I couldn't find

Re: Member access of __gshared global object

2014-08-06 Thread Puming via Digitalmars-d-learn
On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote: 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

Re: Member access of __gshared global object

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 02:00:27AM +, Puming via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote: [...] Indeed, it was just what the OP suspected as the culprit. You are right, I didn't know about the AA initialization problem then. When I

Re: Member access of __gshared global object

2014-08-05 Thread Puming via Digitalmars-d-learn
On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference types, but initially that reference is `null`. When you

Re: Member access of __gshared global object

2014-07-31 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 31 Jul 2014 02:03:35 + Puming via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: 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

Re: Member access of __gshared global object

2014-07-31 Thread via Digitalmars-d-learn
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference types, but initially that reference is `null`. When you write: auto cmds = CONFIG.commands; `cmds` contains a copy

Member access of __gshared global object

2014-07-30 Thread Puming via Digitalmars-d-learn
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();