How does CompilationRelaxations.NoStringInterning actually work?

前端 未结 3 712
渐次进展
渐次进展 2021-01-13 03:42

I am having problems demonstrating NoStringInterning

[assembly: System.Runtime.CompilerServices.CompilationRelaxations(System.Runtime.CompilerServices.Compil         


        
相关标签:
3条回答
  • 2021-01-13 04:16

    The documentation states that the attribute:

    Marks an assembly as not requiring string-literal interning.

    In other words, it does not prevent the compiler from doing string interning, just providing a hint that it is not required. The documentation is a little bit sparse in this area, but this also seems to be the conclusion in this MSDN forum post.

    0 讨论(0)
  • 2021-01-13 04:20

    The MSDN description for NoStringInterning says

    "Marks an assembly as not requiring string-literal interning."

    Saying that an assembly does not require interning is not the same as saying that the feature should be turned off. AFAIK there's no way to do that (except for NGEN).

    0 讨论(0)
  • 2021-01-13 04:28

    Not kick in an opened door, but clearly the attribute doesn't do what you think it does. Documentation for it is quite poor, both in MSDN and the CLI spec. The only thing that's obvious to me from its usage inside the CLR is that, when it is turned on, the compiler only has to ensure that identical strings are interned at the module level. This has a number of side effects that are relevant for inlining, ngen-ed and mixed-mode assemblies.

    That would next force me explain the exact difference between modules and assemblies. Which I can't, modules are strange beasts that have no practical usage in common .NET programming. Best to forget that this attribute is relevant at all. Unless you have a custom build system that runs the C# compiler with the /target:module option, the C# compiler always interns at the assembly level so your test will always produce "true".

    0 讨论(0)
提交回复
热议问题