How does CompilationRelaxations.NoStringInterning actually work?

前端 未结 3 715
渐次进展
渐次进展 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: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".

提交回复
热议问题