Exemplo n.º 1
0
        public void AlignedAllocation <T, TArraySize>(T _)
            where T : unmanaged
        {
            var length = Interop.ComputeRelativeSizeOf <int, T>(1) * 2;

            using var buffer = Accelerator.Allocate <int>(length);
            var viewManager = new TempViewManager(buffer, nameof(buffer));

            viewManager.Allocate <T>(1);
            viewManager.Allocate <T>(1);
        }
Exemplo n.º 2
0
        public void UnalignedAllocation <T, TArraySize>(T _)
            where T : unmanaged
        {
            // NB: The minimum allocation size of TempViewManager is a single integer,
            // so ignore types that are one integer, or smaller, in size. These types
            // will never have alignment issues.
            if (Interop.SizeOf <T>() <= Interop.SizeOf <int>())
            {
                return;
            }

            var length = Interop.ComputeRelativeSizeOf <int, T>(1) + 1;

            using var buffer = Accelerator.Allocate <int>(length);
            var viewManager = new TempViewManager(buffer, nameof(buffer));

            viewManager.Allocate <byte>(1);
            Assert.Throws <InvalidOperationException>(() =>
                                                      viewManager.Allocate <T>(1));
        }