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);
        }
Exemple #2
0
        void AllocateHuge(PooledByteBuffer <T> buf, int reqCapacity)
        {
            PoolChunk <T> chunk = NewUnpooledChunk(reqCapacity);

            _ = Interlocked.Add(ref _activeBytesHuge, chunk.ChunkSize);
            buf.InitUnpooled(chunk, reqCapacity);
            _ = Interlocked.Increment(ref _allocationsHuge);
        }