ServerToolkit.BufferManagement.BufferPool.GetBuffer C# (CSharp) Method

GetBuffer() public method

Creates a buffer of the specified size
public GetBuffer ( long size ) : IBuffer
size long Buffer size, in bytes
return IBuffer
        public IBuffer GetBuffer(long size)
        {
            return GetBuffer(size, null);
        }

Same methods

BufferPool::GetBuffer ( long size, byte filledWith ) : IBuffer

Usage Example

示例#1
0
        public void TryFreeSlabTest()
        {
            long SlabSize = BufferPool.MinimumSlabSize;
            int InitialSlabs = 1;
            int SubsequentSlabs = 3;
            BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs);
            Assert.AreEqual<long>(InitialSlabs, target.SlabCount);

            //GetBuffer of slab size
            IBuffer buff1 = target.GetBuffer(SlabSize);
            //confirm that slabcount is 1
            Assert.AreEqual<long>(InitialSlabs, target.SlabCount);

            //Try to free a slab and do a recount -- slabcount should remain 1
            target.TryFreeSlab();
            Assert.AreEqual<long>(InitialSlabs, target.SlabCount);

            //Get it again to force construction of 3 new slabs
            IBuffer buff2 = target.GetBuffer(SlabSize);
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs, target.SlabCount);

            //Free a slab and do a recount
            target.TryFreeSlab();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 1, target.SlabCount);

            //Free a slab and do a recount -- slabcount should not budge since only one slab is free
            target.TryFreeSlab();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 1, target.SlabCount);

            //Try to free a slab and do a recount
            //Free 1st buffer
            buff1.Dispose();
            target.TryFreeSlab();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 2, target.SlabCount);

            //Try to free a slab and do a recount -- slabcount shouldn't go below two
            target.TryFreeSlab();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 2, target.SlabCount);

            //Free buffer, try to free a slab and do a recount -- slabcount should now be back to 1
            buff2.Dispose();
            target.TryFreeSlab();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 3, target.SlabCount);
        }
All Usage Examples Of ServerToolkit.BufferManagement.BufferPool::GetBuffer