AggressiveInlining doesn't exist

前端 未结 1 645
离开以前
离开以前 2021-01-03 06:58

I was trying to implement OpenSimplex Noise https://gist.github.com/digitalshadow/134a3a02b67cecd72181 in my game, but I\'m getting the error \"\'MethodImplOptions\' does no

1条回答
  •  长发绾君心
    2021-01-03 07:35

    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.

    I don't even know if it's necessary for a program in Unity

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

    I would like to know what to use instead

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

    Why do you think it should work? I'm curious about that. Any sources?

    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
    

    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.

    Another source is from Unity Engineer:

    Little .NET tip: use [MethodImpl(256)] instead of MethodImplOptions.AggressiveInlining to compile on any .NET versions and avoid ifdefs

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