internal bool Allocate(PooledByteBuffer <T> buf, int reqCapacity, int normCapacity)
        {
            if (this.head == null || normCapacity > this.maxCapacity)
            {
                // Either this PoolChunkList is empty or the requested capacity is larger then the capacity which can
                // be handled by the PoolChunks that are contained in this PoolChunkList.
                return(false);
            }

            for (PoolChunk <T> cur = this.head;;)
            {
                long handle = cur.Allocate(normCapacity);
                if (handle < 0)
                {
                    cur = cur.Next;
                    if (cur == null)
                    {
                        return(false);
                    }
                }
                else
                {
                    cur.InitBuf(buf, handle, reqCapacity);
                    if (cur.Usage >= this.maxUsage)
                    {
                        this.Remove(cur);
                        this.nextList.Add(cur);
                    }
                    return(true);
                }
            }
        }
        void AllocateNormal(PooledByteBuffer <T> buf, int reqCapacity, int normCapacity)
        {
            lock (this)
            {
                if (this.q050.Allocate(buf, reqCapacity, normCapacity) || this.q025.Allocate(buf, reqCapacity, normCapacity) ||
                    this.q000.Allocate(buf, reqCapacity, normCapacity) || this.qInit.Allocate(buf, reqCapacity, normCapacity) ||
                    this.q075.Allocate(buf, reqCapacity, normCapacity))
                {
                    ++this.allocationsNormal;
                    return;
                }

                if (this.chunkCount < this.maxChunkCount)
                {
                    // Add a new chunk.
                    PoolChunk <T> c = this.NewChunk(this.PageSize, this.maxOrder, this.PageShifts, this.ChunkSize);
                    this.chunkCount++;
                    long handle = c.Allocate(normCapacity);
                    ++this.allocationsNormal;
                    Contract.Assert(handle > 0);
                    c.InitBuf(buf, handle, reqCapacity);
                    this.qInit.Add(c);
                    return;
                }
            }

            PoolChunk <T> chunk = this.NewUnpooledChunk(reqCapacity, false);

            buf.InitUnpooled(chunk, reqCapacity);
            Interlocked.Increment(ref this.allocationsNormal);
        }
Esempio n. 3
0
        void AllocateNormal(PooledByteBuffer <T> buf, int reqCapacity, int normCapacity)
        {
            if (this.q050.Allocate(buf, reqCapacity, normCapacity) || this.q025.Allocate(buf, reqCapacity, normCapacity) ||
                this.q000.Allocate(buf, reqCapacity, normCapacity) || this.qInit.Allocate(buf, reqCapacity, normCapacity) ||
                this.q075.Allocate(buf, reqCapacity, normCapacity))
            {
                return;
            }

            // Add a new chunk.
            PoolChunk <T> c      = this.NewChunk(this.PageSize, this.maxOrder, this.PageShifts, this.ChunkSize);
            long          handle = c.Allocate(normCapacity);

            Debug.Assert(handle > 0);
            c.InitBuf(buf, handle, reqCapacity);
            this.qInit.Add(c);
        }
Esempio n. 4
0
 protected override void InitBuf(
     PoolChunk <T> chunk, long handle, PooledByteBuffer <T> buf, int reqCapacity, PoolThreadCache <T> threadCache) =>
 chunk.InitBuf(buf, handle, reqCapacity, threadCache);
Esempio n. 5
0
 protected override void InitBuf(
     PoolChunk <T> chunk, long handle, PooledByteBuffer <T> buf, int reqCapacity) =>
 chunk.InitBuf(buf, handle, reqCapacity);