Re: Advantage of const against static readonly?
From: cody (deutronium_at_gmx.de)
Date: 01/16/05
- Next message: thechaosengine: "Where to put my code?"
- Previous message: Uchiha Jax: "Re: Communications between different .NET Applications"
- In reply to: Mattias Sjögren: "Re: Advantage of const against static readonly?"
- Next in thread: Mattias Sjögren: "Re: Advantage of const against static readonly?"
- Reply: Mattias Sjögren: "Re: Advantage of const against static readonly?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 16 Jan 2005 14:09:35 +0100
>>You aren't worried about the memory consumption of a static readonly value
>>which exists exactly one time due to its static nature, are you :)
>
> Not really, no. I'm just pointing out one of the differences. But the
> effect could be quite real if you consider a large enum. If enums were
> built on readonly static fields instead of consts you could probably
> waste a few KB with "useless" static fields taking up memory.
But enums *are* stored somewhere in the assembly there are declared in, or
did I misunderstood you? An Application will stop working if you would
remove the definition of the enum from the library it is using.
>>I suspect that the JIT will generate both both const and static readonly
>>exactly the same code as I cannot imagine a reason why I would not be
>>possible to optimize the code this way.
>
> While it can optimize use of the field, it can't "optimize away" the
> storage location for the static field itself.
Maybe but is the point here? As I poined out earlier you aren't worried
about the memory consumption of a static readonly value which exists exactly
one time :)
But I have indeed found one reason why const can be better than static
readonly field: Accessing a static readonly value forces the static
constructor of that class to run whereas this is not the case with const
values.
- Next message: thechaosengine: "Where to put my code?"
- Previous message: Uchiha Jax: "Re: Communications between different .NET Applications"
- In reply to: Mattias Sjögren: "Re: Advantage of const against static readonly?"
- Next in thread: Mattias Sjögren: "Re: Advantage of const against static readonly?"
- Reply: Mattias Sjögren: "Re: Advantage of const against static readonly?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|