クラスでWrite<T>
関数を使用しようとしています。MemoryMappedViewAccessor
この場合の私T
のは次のとおりです。
[StructLayout(LayoutKind.Explicit)]
public struct Message
{
public void AddString(string str)
{
if (stringContents == null)
stringContents = new byte[1024 * 10];
stringContents = Encoding.ASCII.GetBytes(str);
}
public string GetString()
{
if (stringContents == null)
return string.Empty;
return Encoding.ASCII.GetString(stringContents);
}
[FieldOffset(0)]
public byte[] stringContents;
}
ただし、次のような電話をかけると:
//Initialized Elsewhere: MemoryMappedViewAccessor writer
Message messageAlreadyOnWire = new Message();
messageAlreadyOnWire.AddString(data);
writer.Write<Message>(0, ref messageAlreadyOnWire);
次のようなエラーが表示されます。
指定された Type は、参照を含まない構造体でなければなりません。パラメータ名: タイプ
私の構造体の唯一の「参照」はバイト配列です。この問題を解決する方法はありますか? 私は固定長のバイト配列で問題ありませんが、 の土地を掘り下げずに宣言する方法がわかりunsafe
ません。