Example #1
0
        public static void OwnedMemoryPinEmptyArray()
        {
            int[]             a      = {};
            OwnedMemory <int> owner  = new CustomMemoryForTest <int>(a);
            MemoryHandle      handle = owner.Pin();

            Assert.True(handle.HasPointer);
        }
Example #2
0
        public static void MemoryManagerPinEmptyArray()
        {
            int[] a = { };
            MemoryManager <int> manager = new CustomMemoryForTest <int>(a);
            MemoryHandle        handle  = manager.Pin();

            unsafe
            {
                Assert.True(handle.Pointer != null);
            }
        }
Example #3
0
        public static void OwnedMemoryPinArray()
        {
            int[]             array  = { 1, 2, 3, 4, 5 };
            OwnedMemory <int> owner  = new CustomMemoryForTest <int>(array);
            MemoryHandle      handle = owner.Pin();

            Assert.True(handle.HasPointer);
            unsafe
            {
                int *pointer = (int *)handle.Pointer;

                GC.Collect();

                for (int i = 0; i < owner.Memory.Length; i++)
                {
                    Assert.Equal(array[i], pointer[i]);
                }
            }
            handle.Dispose();
        }
Example #4
0
        public static void MemoryManagerPinArray()
        {
            int[] array = { 1, 2, 3, 4, 5 };
            MemoryManager <int> manager = new CustomMemoryForTest <int>(array);
            MemoryHandle        handle  = manager.Pin();

            unsafe
            {
                int *pointer = (int *)handle.Pointer;
                Assert.True(pointer != null);

                GC.Collect();

                for (int i = 0; i < manager.Memory.Length; i++)
                {
                    Assert.Equal(array[i], pointer[i]);
                }
            }
            handle.Dispose();
        }