本文介绍了AggressiveInlining不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施OpenSimplex Noise https://gist.github.com/digitalshadow/134a3a02b67cecd72181 ,但是出现错误'MethodImplOptions'不包含'AggressiveInlining'的定义".

I was trying to implement OpenSimplex Noise https://gist.github.com/digitalshadow/134a3a02b67cecd72181 in my game, but I'm getting the error "'MethodImplOptions' does not contain a definition for 'AggressiveInlining'".

[ MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static int FastFloor(double x)
    {
        var xi = (int)x;
        return x < xi ? xi - 1 : xi;
    }

是的,我包括了using System.Runtime.CompilerServices;.现在,老实说,我不知道内联是如何工作的,所以我什至不知道对于Unity中的程序来说是否有必要.如果我不需要它,我想知道该用什么.预先感谢.

Yes, I included using System.Runtime.CompilerServices;. Now, I'll be perfectly honest, I don't know how inlining works, so I don't even know if it's necessary for a program in Unity. If I don't need it, I would like to know what to use instead. Thanks in advance.

推荐答案

MethodImplOptions.AggressiveInlining枚举不存在,因为在Unity仍使用的情况下,此功能是在 .NET 4.5 中添加的. NET 2.0/3.5 .

The MethodImplOptions.AggressiveInlining enum does not exist because this feature was added in .NET 4.5 while Unity is still using .NET 2.0/3.5.

这不是必需的,但似乎可以加快函数调用的速度.您可以在此处看到速度测试.

It's not necessary but it seems to speed up function calling. You can see a speed test here.

您可以使用[MethodImpl(256)]代替MethodImplOptions.AggressiveInlining.那也应该工作.

You can use [MethodImpl(256)] instead of MethodImplOptions.AggressiveInlining. That should work too.

在下面的 MethodImplOptions 枚举中查看源代码:

Look at the source code for the MethodImplOptions enum below:

public enum MethodImplOptions {
        Unmanaged = 4,
        ForwardRef = 16,
        InternalCall = 4096,
        Synchronized = 32,
        NoInlining = 8,
        PreserveSig = 128,
        NoOptimization = 64,
#if NET_4_5
        AggressiveInlining  = 256,
#endif
    } // MethodImplOptions

如您所见,AggressiveInlining的值为256.当您使用 MethodImplAttribute 构造时如果使用int参数重载,则基本上可以使用任何不存在的enum值.传递256可以在任何.NET版本上为您提供AggressiveInlining.新的枚举值仅仅是为了使它更容易记住/使用而已.

As you can see, AggressiveInlining has a value of 256. When you use the MethodImplAttribute construction overload with the int parameter, you can essentially use any enum value that does not exist. Passing it 256 should give you AggressiveInlining on any .NET version. The new enum value is simply there to make it easier to remember/use.

另一个来源来自Unity工程师:

Another source is from Unity Engineer:

这篇关于AggressiveInlining不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 05:24