更新时间:2022-05-22 02:53:02
忽略我以前发布的内容,我在某种程度上使事情变得过于复杂了!当需要将未知长度的数据进行编组时,可以使用我建议的方法.
如您所知,它很简单:
Ignore what I posted previously, I was somewhat overcomplicating things! The method I suggested can be used when an unknown length of data is required to be marshalled.
As you know the length, it''s simple:
[StructLayout(LayoutKind.Sequential)]
struct Inner
{
public uint A;
public byte B;
}
[StructLayout(LayoutKind.Sequential)]
struct Foo
{
public ushort W;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] X;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public Inner[] data;
}
为什么要使用fixed
和unsafe
?
Why are you using fixed
and unsafe
?