static void StackSample() { Span <byte> span = stackalloc byte[10]; SampleImport.SAMPLE_NumberSequence_UseRef(ref span[0], span.Length); Console.WriteLine(ToString(span)); }
static void ArraySample() { var bytes = new byte[10]; SampleImport.SAMPLE_NumberSequence_UseRef(ref bytes[0], bytes.Length); Console.WriteLine(ToString(bytes)); }
static void SpanSample() { var bytes = new byte[10]; var span = bytes.AsSpan(); SampleImport.SAMPLE_NumberSequence_UseRef(ref span[0], span.Length); Console.WriteLine(ToString(bytes)); }
static void WritebackSample() { var p = SampleImport.SAMPLE_Create(); { var d = new Dummy { Index = 10, Value = new Vector3 { X = 1, Y = 2, Z = -3, }, }; Marshal.StructureToPtr(d, p, true); } SampleImport.SAMPLE_Print(p); SampleImport.SAMPLE_Destroy(p); }
static void WritebackCast() { var p = SampleImport.SAMPLE_Create(); unsafe { var pd = (Dummy *)p; * pd = new Dummy { Index = 10, Value = new Vector3 { X = 1, Y = 2, Z = -3, }, }; } SampleImport.SAMPLE_Print(p); SampleImport.SAMPLE_Destroy(p); }
static void WritebackStack() { var p = SampleImport.SAMPLE_Create(); // さすがに必要 unsafe { var span = new Span <Dummy>((void *)p, 1); span[0] = new Dummy { Index = 10, Value = new Vector3 { X = 1, Y = 2, Z = -3, }, }; } SampleImport.SAMPLE_Print(p); SampleImport.SAMPLE_Destroy(p); }