我有一个字节数组,我想将它重新解释为一个 blittable 结构数组,最好不要复制。使用不安全的代码很好。我知道字节数,以及我想在最后得到的结构数。
public struct MyStruct
{
public uint val1;
public uint val2;
// yadda yadda yadda....
}
byte[] structBytes = reader.ReadBytes(byteNum);
MyStruct[] structs;
fixed (byte* bytes = structBytes)
{
structs = // .. what goes here?
// the following doesn't work, presumably because
// it doesnt know how many MyStructs there are...:
// structs = (MyStruct[])bytes;
}