コード例 #1
0
        public static unsafe void WrapArray()
        {
            int[] array = { 10, 20 };
            using var rental = new MemoryRental <int>(array);
            False(rental.IsEmpty);
            fixed(int *ptr = rental)
            {
                Equal(10, *ptr);
            }

            True(AreSame(ref rental[0], ref array[0]));
        }
コード例 #2
0
 public static unsafe void StackAllocationTest()
 {
     using MemoryRental <int> vector = stackalloc int[4];
     False(vector.IsEmpty);
     Equal(4, vector.Length);
     Equal(4, vector.Span.Length);
     vector[0] = 10;
     vector[1] = 20;
     vector[2] = 30;
     vector[3] = 40;
     Equal(10, vector.Span[0]);
     Equal(20, vector.Span[1]);
     Equal(30, vector.Span[2]);
     Equal(40, vector.Span[3]);
 }
コード例 #3
0
        public static void Default()
        {
            var rental = new MemoryRental <int>(Array.Empty <int>());

            True(rental.IsEmpty);
            Equal(0, rental.Length);
            True(rental.Span.IsEmpty);
            rental.Dispose();

            rental = default;
            True(rental.IsEmpty);
            Equal(0, rental.Length);
            True(rental.Span.IsEmpty);
            rental.Dispose();
        }
コード例 #4
0
 public static void HeapAllocationTest()
 {
     using var vector = new MemoryRental <int>(4);
     False(vector.IsEmpty);
     Equal(4, vector.Length);
     Equal(4, vector.Span.Length);
     vector[0] = 10;
     vector[1] = 20;
     vector[2] = 30;
     vector[3] = 40;
     Equal(10, vector.Span[0]);
     Equal(20, vector.Span[1]);
     Equal(30, vector.Span[2]);
     Equal(40, vector.Span[3]);
 }