Unsafe C# trick to improve speed

后端 未结 3 2152
花落未央
花落未央 2021-02-19 14:02

I am not used to code with pointers (e.g. C++), nor with unsafe islands: only \"safe\" C#. Now I\'d like to implement a function in C# for the .Net Micro Framework, where the co

3条回答
  •  清酒与你
    2021-02-19 14:24

    Look at this example from a different posting, on some code I have used extensively. You have the correct idea, just need to set the FieldOffset() values, and then use the fixed() keyword when accessing the data.

    This method is quite reliable, but not really much faster. The reason I use it, is because when I have lots of fields I want a quick way of accessing them as an array.

提交回复
热议问题