ServiceStack.Text.RecyclableMemoryStreamManager.GetBlock C# (CSharp) Method

GetBlock() private method

Removes and returns a single block from the pool.
private GetBlock ( ) : byte[]
return byte[]
        internal byte[] GetBlock()
        {
            byte[] block;
            if (!this.smallPool.TryPop(out block))
            {
                // We'll add this back to the pool when the stream is disposed
                // (unless our free pool is too large)
                block = new byte[this.BlockSize];
                Events.Write.MemoryStreamNewBlockCreated(this.smallPoolInUseSize);

                if (this.BlockCreated != null)
                {
                    this.BlockCreated();
                }
            }
            else
            {
                Interlocked.Add(ref this.smallPoolFreeSize, -this.BlockSize);
            }

            Interlocked.Add(ref this.smallPoolInUseSize, this.BlockSize);
            return block;
        }