Assigning global and static associative arrays

Timon Gehr timon.gehr at gmx.ch
Sun Sep 2 09:20:48 PDT 2012


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 allocated. And on Linux at least, as I understand it, the
>> string literals go in ROM. But it may be that the above code functions
>> differently in Windows, since it _doesn't_ put string literals in ROM.
>> [SNIP]
>
> 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 could use a static immutable instead?
>
> If I understood correctly, the enum will *always* be inlined
> (doesn't create any actual symbols). But if you use a static
> immutable, then the compiler will create an actual symbol, but
> probably inline it away if it judges that is a better choice
> anyways...
>
> Is there *any* scenario where one would choose the enum over the
> static immutable...?

- If there is no need to access it at run time.
- Type deduction.


More information about the Digitalmars-d-learn mailing list