Ejemplo n.º 1
0
        protected override IByteBuffer NewBuffer(int initialCapacity, int maxCapacity)
        {
            if (initialCapacity > this.MaxPooledBufSize)
            {
                return(new UnpooledHeapByteBuffer(this, initialCapacity, maxCapacity));
            }

            PooledByteBuffer buffer = this.pool.Take();

            buffer.Init();
            return(buffer);
        }
Ejemplo n.º 2
0
        void InitBufWithSubpage(PooledByteBuffer <T> buf, long handle, int bitmapIdx, int reqCapacity)
        {
            Contract.Assert(bitmapIdx != 0);

            int memoryMapIdx = MemoryMapIdx(handle);

            PoolSubpage <T> subpage = this.subpages[this.SubpageIdx(memoryMapIdx)];

            Contract.Assert(subpage.DoNotDestroy);
            Contract.Assert(reqCapacity <= subpage.ElemSize);

            buf.Init(
                this, handle,
                this.RunOffset(memoryMapIdx) + (bitmapIdx & 0x3FFFFFFF) * subpage.ElemSize, reqCapacity, subpage.ElemSize,
                this.Arena.Parent.ThreadCache <T>());
        }
Ejemplo n.º 3
0
        void InitBufWithSubpage(PooledByteBuffer <T> buf, long handle, int bitmapIdx, int reqCapacity, PoolThreadCache <T> threadCache)
        {
            Debug.Assert(bitmapIdx != 0);

            int memoryMapIdx = MemoryMapIdx(handle);

            PoolSubpage <T> subpage = _subpages[SubpageIdx(memoryMapIdx)];

            Debug.Assert(subpage.DoNotDestroy);
            Debug.Assert(reqCapacity <= subpage.ElemSize);

            buf.Init(
                this, handle,
                RunOffset(memoryMapIdx) + (bitmapIdx & 0x3FFFFFFF) * subpage.ElemSize + Offset,
                reqCapacity, subpage.ElemSize, threadCache);
        }
Ejemplo n.º 4
0
        internal void InitBuf(PooledByteBuffer <T> buf, long handle, int reqCapacity, PoolThreadCache <T> threadCache)
        {
            int memoryMapIdx = MemoryMapIdx(handle);
            int bitmapIdx    = BitmapIdx(handle);

            if (0u >= (uint)bitmapIdx)
            {
                sbyte val = Value(memoryMapIdx);
                Debug.Assert(val == _unusable, val.ToString());
                buf.Init(this, handle, RunOffset(memoryMapIdx) + Offset, reqCapacity, RunLength(memoryMapIdx), threadCache);
            }
            else
            {
                InitBufWithSubpage(buf, handle, bitmapIdx, reqCapacity, threadCache);
            }
        }
Ejemplo n.º 5
0
        internal void InitBuf(PooledByteBuffer <T> buf, long handle, int reqCapacity)
        {
            int memoryMapIdx = MemoryMapIdx(handle);
            int bitmapIdx    = BitmapIdx(handle);

            if (bitmapIdx == 0)
            {
                sbyte val = this.Value(memoryMapIdx);
                Contract.Assert(val == this.unusable, val.ToString());
                buf.Init(this, handle, this.RunOffset(memoryMapIdx), reqCapacity, this.RunLength(memoryMapIdx),
                         this.Arena.Parent.ThreadCache <T>());
            }
            else
            {
                this.InitBufWithSubpage(buf, handle, bitmapIdx, reqCapacity);
            }
        }