Ejemplo n.º 1
0
        public void AllocateGroup_BufferSizesAreCorrect <T>(
            T dummy,
            int sharedArrayPoolThresholdInBytes,
            int maxContiguousPoolBufferInBytes,
            int maxPoolSizeInBytes,
            int maxCapacityOfUnmanagedBuffers,
            long allocationLengthInElements,
            int bufferAlignmentInElements,
            int expectedNumberOfBuffers,
            int expectedBufferSize,
            int expectedSizeOfLastBuffer)
            where T : struct
        {
            var allocator = new UniformUnmanagedMemoryPoolMemoryAllocator(
                sharedArrayPoolThresholdInBytes,
                maxContiguousPoolBufferInBytes,
                maxPoolSizeInBytes,
                maxCapacityOfUnmanagedBuffers);

            using MemoryGroup <T> g = allocator.AllocateGroup <T>(allocationLengthInElements, bufferAlignmentInElements);
            MemoryGroupTests.Allocate.ValidateAllocateMemoryGroup(
                expectedNumberOfBuffers,
                expectedBufferSize,
                expectedSizeOfLastBuffer,
                g);
        }
Ejemplo n.º 2
0
        public unsafe void Allocate_MemoryIsPinnableMultipleTimes()
        {
            var allocator = new UniformUnmanagedMemoryPoolMemoryAllocator(null);

            using IMemoryOwner <byte> memoryOwner = allocator.Allocate <byte>(100);

            using (MemoryHandle pin = memoryOwner.Memory.Pin())
            {
                Assert.NotEqual(IntPtr.Zero, (IntPtr)pin.Pointer);
            }

            using (MemoryHandle pin = memoryOwner.Memory.Pin())
            {
                Assert.NotEqual(IntPtr.Zero, (IntPtr)pin.Pointer);
            }
        }
Ejemplo n.º 3
0
        public void AllocateGroup_MultipleTimes_ExceedPoolLimit()
        {
            var allocator = new UniformUnmanagedMemoryPoolMemoryAllocator(
                64,
                128,
                1024,
                1024);

            var groups = new List <MemoryGroup <S4> >();

            for (int i = 0; i < 16; i++)
            {
                int lengthInElements = 128 / Unsafe.SizeOf <S4>();
                MemoryGroup <S4> g   = allocator.AllocateGroup <S4>(lengthInElements, 32);
                MemoryGroupTests.Allocate.ValidateAllocateMemoryGroup(1, -1, lengthInElements, g);
                groups.Add(g);
            }

            foreach (MemoryGroup <S4> g in groups)
            {
                g.Dispose();
            }
        }