public ArraySegment <byte> TakeBuffer(int bufferSize)
        {
            int num;

            if (bufferSize > this.segmentSize)
            {
                throw new ArgumentOutOfRangeException("bufferSize");
            }
            lock (this.lockObject)
            {
                if (this.top < 0)
                {
                    num = -1;
                }
                else
                {
                    num = this.offsets[this.top];
                    SegmentBufferPool segmentBufferPool = this;
                    segmentBufferPool.top = segmentBufferPool.top - 1;
                }
            }
            if (num < 0)
            {
                return(new ArraySegment <byte>(new byte[bufferSize]));
            }
            return(new ArraySegment <byte>(this.heap, num, bufferSize));
        }
 public void ReturnBuffer(ArraySegment <byte> buffer)
 {
     if (buffer.Array == this.heap)
     {
         lock (this.lockObject)
         {
             if (this.top < (int)this.offsets.Length - 1)
             {
                 SegmentBufferPool segmentBufferPool = this;
                 segmentBufferPool.top  = segmentBufferPool.top + 1;
                 this.offsets[this.top] = buffer.Offset;
             }
         }
     }
 }