コード例 #1
0
        public void Rent_Success_ExponentialSizes_WithReturn(int minSize)
        {
            var cache = new GenericArrayPoolCaches <byte>();
            var item  = cache.Rent(minSize);

            // The item rented is perfect power of two size so the size of the buffer should be exactly min size
            item.Length.Should().Be(minSize);

            cache.Return(ref item);
            item.Should().BeNull();

            if (minSize > 2)
            {
                var item2 = cache.Rent(minSize - 1);
                // The item rented is one less than perfect power of two size so the size of the buffer should be exactly min size
                item2.Length.Should().Be(minSize);

                cache.Return(ref item2);
                item2.Should().BeNull();

                var item3 = cache.Rent(minSize + 1);
                // The item rented is one less than perfect power of two size so the size of the buffer should be exactly twice min size
                item3.Length.Should().Be(minSize + 1 > GenericArrayPoolCaches <byte> .MAX_BUFFER_SIZE_CACHED ? minSize + 1 : 2 * minSize);

                cache.Return(ref item3);
                item3.Should().BeNull();
            }
        }
コード例 #2
0
            public void GenericArrayPool_T_RentAndReturn_CachedObjectImpl_SimgleItem()
            {
                for (int i = 0; i < 20; i++)
                {
                    byte[] b = _genericArrayPoolObj.Rent(1 << i + 1);

                    _genericArrayPoolObj.Return(ref b);
                }
            }
コード例 #3
0
        public void Return_Fail_PoolCacheIsFull()
        {
            var cache = new GenericArrayPoolCaches <byte>();

            // Fill a small pool with returned elements of the correct size
            for (int i = 0; i < GenericArrayPoolCaches <byte> .DEFAULT_POOL_CACHE_SIZES[3]; i++)
            {
                var b = new byte[8];
                cache.Return(ref b);
            }

            // Return an additional element. This should not throw an exception but may
            // record an item in the log
            var b2 = new byte[8];

            cache.Return(ref b2);
        }
コード例 #4
0
        public void Return_Fail_InvalidBufferSize()
        {
            var cache = new GenericArrayPoolCaches <byte>();

            // This should not throw an exception but may record an item in the log
            var b = new byte[7];

            cache.Return(ref b);
        }
コード例 #5
0
        public void Return_Fail_BufferTooLarge()
        {
            var cache = new GenericArrayPoolCaches <byte>();

            var b = new byte[1 << 21];

            // This should not throw an exception but may record an item in the log
            cache.Return(ref b);
        }