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); }