Search code examples
c#.netoptimization

What are relaxed exceptions in .NET / C#?


I found the CompilationRelaxations attribute on an assembly when looking at it in Reflector. This link says that the attribute specifies whether:

Optimizers are granted additional latitude for relaxed exceptions.

What are relaxed exceptions and what does the compiler do given its "additional latitude" with them.


Solution

  • This allows the compiler to have more flexibility in it's optimization.

    See the help for the CompilationRelaxations enum for details.

    --- EDIT ---

    At this point, there is a single enum that attribute uses, with only 1 option: NoStringInterning

    From the MSDN help, this:

    Marks an assembly as not requiring string-literal interning.
    
    In an application domain, the common language runtime creates one string 
    object for each unique string literal, rather than making multiple copies.
    This behavior, called string interning, internally requires building 
    auxiliary tables that consume memory resources. 
    

    This attribute is specified to use an enum, though, so more options can easily be added later. This is the only optimization allowed via this assembly attribute right now, though.