C# unsafe value type array to byte array conversions

后端 未结 7 755
梦毁少年i
梦毁少年i 2020-11-30 08:20

I use an extension method to convert float arrays into byte arrays:

public static unsafe byte[] ToByteArray(this float[] floatArray, int count)
{
    int arr         


        
相关标签:
7条回答
  • 2020-11-30 08:48

    You should check my answer to a similar question: What is the fastest way to convert a float[] to a byte[]?.

    In it you'll find portable code (32/64 bit compatible) to let you view a float array as a byte array or vice-versa, without copying the data. It's the fastest way that I know of to do such thing.

    If you're just interested in the code, it's maintained at https://gist.github.com/1050703 .

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