如何强制内联函数在C#中? [英] How to force inline functions in C#?
问题描述
可能重复:结果
的内联函数在C#?
在C ++中,我们可以强制<一个HREF =http://en.wikipedia.org/wiki/Inline_function>函数内联。
In c++ we can force function inlining.
在C#中,这也可能吗?有时,当方法是小的,它被自动内联。但在C#中有可能力内联函数/。NET?
Is this also possible in c#? sometimes, and when the method is small, it gets inlined automatically. But is it possible force inlining functions in c#/.Net?
推荐答案
排序。这不是你的直接控制下打开的在的肯定。这是从来没有在IL内联 - 它只是由JIT完成
Sort of. It's not under your direct control to turn on for sure. It's never inlined in the IL - it's only done by the JIT.
您可以明确强制法的不的使用内联的 MethodImplAttribute
You can explicitly force a method to not be inlined using MethodImplAttribute
[MethodImpl(MethodImplOptions.NoInlining)]
public void Foo() { ... }
您也可以排序的请求内联作为.NET 4.5的:
You can also sort of "request" inlining as of .NET 4.5:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Foo() { ... }
...但你不能强迫它。 (在此之前.NET 4.5,即枚举值不存在。请参阅的。NET 4文档,例如。)
... but you can't force it. (Prior to .NET 4.5, that enum value didn't exist. See the .NET 4 documentation, for example.)
这篇关于如何强制内联函数在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!