示例#1
0
        public void Reserve(long capacity)
        {
            if (capacity <= Capacity)
            {
                return;
            }

            var newBuffer = ReusableByteBufferManager.GetBuffer(capacity);

            if (this.length > 0)
            {
                if (this.bufferValidFrom < this.bufferValidTo)
                {
                    Array.Copy(this.reusableBuffer.Buffer, this.bufferValidFrom, newBuffer.Buffer, 0, this.length);
                }
                else
                {
                    Array.Copy(this.reusableBuffer.Buffer, this.bufferValidFrom, newBuffer.Buffer, 0, Capacity - this.bufferValidFrom);
                    Array.Copy(this.reusableBuffer.Buffer, 0, newBuffer.Buffer, Capacity - this.bufferValidFrom, this.bufferValidTo);
                }
            }

            this.reusableBuffer.Dispose();
            this.reusableBuffer = newBuffer;

            this.bufferValidFrom = 0;
            this.bufferValidTo   = this.length;
        }
示例#2
0
 public CircularMemoryStream(int baseCapacity = 0, FeedOverflowMode feedOverflowMode = FeedOverflowMode.ExtendCapacity)
 {
     this.overflowMode = feedOverflowMode;
     if (feedOverflowMode == FeedOverflowMode.ExtendCapacity && baseCapacity == 0)
     {
         this.reusableBuffer = ReusableByteBufferManager.GetBuffer();
     }
     else
     {
         this.reusableBuffer = ReusableByteBufferManager.GetBuffer(baseCapacity);
     }
 }