Beispiel #1
0
        static void StackSample()
        {
            Span <byte> span = stackalloc byte[10];

            SampleImport.SAMPLE_NumberSequence_UseRef(ref span[0], span.Length);
            Console.WriteLine(ToString(span));
        }
Beispiel #2
0
        static void ArraySample()
        {
            var bytes = new byte[10];

            SampleImport.SAMPLE_NumberSequence_UseRef(ref bytes[0], bytes.Length);
            Console.WriteLine(ToString(bytes));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }