Re: Assigning global and static associative arrays

2012-09-02 Thread Ali Çehreli
On 09/02/2012 12:24 PM, Philippe Sigaud wrote: > On Sun, Sep 2, 2012 at 8:50 PM, Ali Çehreli wrote: >> On 09/02/2012 06:45 AM, monarch_dodra wrote: >> >>> Is there *any* scenario where one would choose the enum over the >>> static immutable...? > > Due to Jonathan advice, I converted a part of my

Re: Assigning global and static associative arrays

2012-09-02 Thread Philippe Sigaud
On Sun, Sep 2, 2012 at 8:50 PM, Ali Çehreli wrote: > On 09/02/2012 06:45 AM, monarch_dodra wrote: > >> Is there *any* scenario where one would choose the enum over the >> static immutable...? Due to Jonathan advice, I converted a part of my code (enum => static this). At runtime, I got a 40% decr

Re: Assigning global and static associative arrays

2012-09-02 Thread Ali Çehreli
On 09/02/2012 06:45 AM, monarch_dodra wrote: > Is there *any* scenario where one would choose the enum over the > static immutable...? That's a good question. If Timon Gehr's example is the only difference, I wonder whether the guidelines that I had come up with are still valuable? I would app

Re: Assigning global and static associative arrays

2012-09-02 Thread Timon Gehr
On 09/02/2012 06:26 PM, monarch_dodra wrote: On Sunday, 2 September 2012 at 16:20:16 UTC, Timon Gehr wrote: On 09/02/2012 03:45 PM, monarch_dodra wrote: FYI: I get the exact same behavior in Windows. Not that it matters, but it sounded like you were asking. I'm a bit confused now though: Why

Re: Assigning global and static associative arrays

2012-09-02 Thread monarch_dodra
On Sunday, 2 September 2012 at 16:20:16 UTC, Timon Gehr wrote: On 09/02/2012 03:45 PM, monarch_dodra wrote: FYI: I get the exact same behavior in Windows. Not that it matters, but it sounded like you were asking. I'm a bit confused now though: Why would someone want to use an enum when they co

Re: Assigning global and static associative arrays

2012-09-02 Thread Timon Gehr
On 09/02/2012 03:45 PM, monarch_dodra wrote: On Saturday, 1 September 2012 at 09:16:30 UTC, Jonathan M Davis wrote: [SNIP] so it looks like not only do all instances of the same string enum use the same memory, but another enum with the same string literal shares it as well. So, only one is allo

Re: Assigning global and static associative arrays

2012-09-02 Thread monarch_dodra
On Saturday, 1 September 2012 at 09:16:30 UTC, Jonathan M Davis wrote: [SNIP] so it looks like not only do all instances of the same string enum use the same memory, but another enum with the same string literal shares it as well. So, only one is allocated. And on Linux at least, as I understa

Re: Assigning global and static associative arrays

2012-09-01 Thread Jonathan M Davis
On Saturday, September 01, 2012 11:10:17 Jonathan M Davis wrote: > On Saturday, September 01, 2012 16:14:29 ixid wrote: > > Those still have different addresses when made immutable too, is > > this something that could be optimized for all immutable enums to > > behave like strings or are there rea

Re: Assigning global and static associative arrays

2012-09-01 Thread Jonathan M Davis
On Saturday, September 01, 2012 16:14:29 ixid wrote: > Those still have different addresses when made immutable too, is > this something that could be optimized for all immutable enums to > behave like strings or are there reasons to keep them unique at > each instance? The compiler has to got to

Re: Assigning global and static associative arrays

2012-09-01 Thread ixid
Those still have different addresses when made immutable too, is this something that could be optimized for all immutable enums to behave like strings or are there reasons to keep them unique at each instance?

Re: Assigning global and static associative arrays

2012-09-01 Thread Jonathan M Davis
On Saturday, September 01, 2012 11:07:34 Philippe Sigaud wrote: > > Using enum can be very useful, but I wouldn't use it for AAs at all, and > > I'd be leery of using it for much in the way of arrays other than string > > literals (since the string literals should avoid the memory allocations > > t

Re: Assigning global and static associative arrays

2012-09-01 Thread Philippe Sigaud
> Using enum can be very useful, but I wouldn't use it for AAs at all, and I'd > be leery of using it for much in the way of arrays other than string literals > (since the string literals should avoid the memory allocations that other > array literals get). It's fine most other stuff, but for those

Re: Assigning global and static associative arrays

2012-09-01 Thread Jonathan M Davis
On Saturday, September 01, 2012 09:39:04 Philippe Sigaud wrote: > On Sat, Sep 1, 2012 at 12:21 AM, Jonathan M Davis wrote: > > Using an enum is particularly bad for an AA, since it's not exactly a > > simple data type, and there's definitely some cost to constructing them. > > Yeah, my (nasty) b

Re: Assigning global and static associative arrays

2012-09-01 Thread Philippe Sigaud
On Sat, Sep 1, 2012 at 12:21 AM, Jonathan M Davis wrote: > Using an enum is particularly bad for an AA, since it's not exactly a simple > data type, and there's definitely some cost to constructing them. Yeah, my (nasty) bad. I'm too used to put 'enum' everywhere. Gosh, I confirm using static t

Re: Assigning global and static associative arrays

2012-08-31 Thread Jonathan M Davis
On Saturday, September 01, 2012 00:12:06 ixid wrote: > Hmm, you mean if you call the same function it creates a new copy > every time? I misunderstood you to mean it creates it once at > each site in the code it's called. enum values are basically copy-pasted everywhere that they're used. So, if y

Re: Assigning global and static associative arrays

2012-08-31 Thread ixid
Hmm, you mean if you call the same function it creates a new copy every time? I misunderstood you to mean it creates it once at each site in the code it's called.

Re: Assigning global and static associative arrays

2012-08-31 Thread ixid
Yep, I am aware of that, for my use it happens to be perfect but I understand that having a bunch of copies all over the place wouldn't be smart.

Re: Assigning global and static associative arrays

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 10:34 PM, ixid wrote: > Philippe suggested enum allowing this: > > enum dayNumbers = [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, > > "Thursday" : 3, "Friday" : 4, "Saturday" : 5, > "Sunday" : 6 ]; > > Why does this seem to avoid pointer issues? Is it creating a compil

Re: Assigning global and static associative arrays

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 9:56 PM, Jonathan M Davis wrote: > Except that that allocates a new AA every time that you use dayNumbers. So, > that's probably a bad idea. Oh! I keep forgetting that enums are replaced by their values. Then I think I know where some problem I had came from. Damn, just

Re: Assigning global and static associative arrays

2012-08-31 Thread ixid
Philippe suggested enum allowing this: enum dayNumbers = [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, "Thursday" : 3, "Friday" : 4, "Saturday" : 5, "Sunday" : 6 ]; Why does this seem to avoid pointer issues? Is it creating a compile-time associated array or run-time?

Re: Assigning global and static associative arrays

2012-08-31 Thread Jonathan M Davis
On Friday, August 31, 2012 20:24:27 Philippe Sigaud wrote: > On Fri, Aug 31, 2012 at 7:04 PM, ixid wrote: > > Thank you, that certainly makes sense. > > If you're certain you won't need to modify it, you can make it a > compile-time constant: > > enum int[string] dayNumbers = > [ "Monday" : 0, "

Re: Assigning global and static associative arrays

2012-08-31 Thread Philippe Sigaud
On Fri, Aug 31, 2012 at 7:04 PM, ixid wrote: > Thank you, that certainly makes sense. If you're certain you won't need to modify it, you can make it a compile-time constant: enum int[string] dayNumbers = [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, "Thursday" : 3, "Friday"

Re: Assigning global and static associative arrays

2012-08-31 Thread ixid
Thank you, that certainly makes sense.

Re: Assigning global and static associative arrays

2012-08-31 Thread Jonathan M Davis
On Friday, August 31, 2012 16:38:13 ixid wrote: > Why does this not work: > > int[string] dayNumbers = > [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, > "Thursday" : 3, "Friday" : 4, "Saturday" : 5, > "Sunday" : 6 ]; > > void main() { > //Stuff > } > > With the error 'non-constant expression'?

Re: Assigning global and static associative arrays

2012-08-31 Thread Mike Parker
On 9/1/2012 1:31 AM, Mike Parker wrote: On 8/31/2012 11:38 PM, ixid wrote: Why does this not work: int[string] dayNumbers = [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, "Thursday" : 3, "Friday" : 4, "Saturday" : 5, "Sunday" : 6 ]; void main() { //St

Re: Assigning global and static associative arrays

2012-08-31 Thread Mike Parker
On 8/31/2012 11:38 PM, ixid wrote: Why does this not work: int[string] dayNumbers = [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, "Thursday" : 3, "Friday" : 4, "Saturday" : 5, "Sunday" : 6 ]; void main() { //Stuff } With the error 'non-constant expre

Assigning global and static associative arrays

2012-08-31 Thread ixid
Why does this not work: int[string] dayNumbers = [ "Monday" : 0, "Tuesday" : 1, "Wednesday" : 2, "Thursday" : 3, "Friday" : 4, "Saturday" : 5, "Sunday" : 6 ]; void main() { //Stuff } With the error 'non-constant expression'? This error also seems to preven