[Mono-list] ikvm and Mono 0.20

Paolo Molaro lupus@ximian.com
Wed, 26 Feb 2003 21:31:39 +0100


On 02/26/03 Philippe Lavoie wrote:
> Why not tag the class with an attribute?
> 
> [InitStaticOnFirstUseOnly]
> public static class Bob {
> }
> 
> The InitStaticOnFirstUseOnly would just mean that the compiler needs to
> create a transparent singleton static proxy for that class.
> 
> This way, current implementation stays the same and the programmer is
> (or might be) aware that relying on InitStaticOnFirstUseOnly will come
> with a slight performance hit.
> 
> Unless ECMA states when static is created. Personally, I though it was
> always at start-up time. I didn't know MS.NET did it on 'first use'.

There is already a flag in the type that relaxes the restrictions,
though it's not set by the compiler by default (beforefieldinit).
I should also note that the extra function call is needed only when a
static field is accessed from a different class, because otherwise, the
class initializations was already triggered by the call to the current
method.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better