private void EnsureCapacity(int newCapacity)
{
if (newCapacity > this.memoryManager.MaximumStreamCapacity && this.memoryManager.MaximumStreamCapacity > 0)
{
Events.Write.MemoryStreamOverCapacity(newCapacity, this.memoryManager.MaximumStreamCapacity, this.tag, this.allocationStack);
throw new InvalidOperationException("Requested capacity is too large: " + newCapacity + ". Limit is " + this.memoryManager.MaximumStreamCapacity);
}
if (this.largeBuffer != null)
{
if (newCapacity > this.largeBuffer.Length)
{
var newBuffer = this.memoryManager.GetLargeBuffer(newCapacity, this.tag);
this.InternalRead(newBuffer, 0, this.length, 0);
this.ReleaseLargeBuffer();
this.largeBuffer = newBuffer;
}
}
else
{
while (this.Capacity < newCapacity)
{
blocks.Add((this.memoryManager.GetBlock()));
}
}
}