void ChangeQuota(ref BufferPool bufferPool, int delta)
{
BufferPool oldBufferPool = bufferPool;
int newLimit = oldBufferPool.Limit + delta;
BufferPool newBufferPool = BufferPool.CreatePool(oldBufferPool.BufferSize, newLimit);
for (int i = 0; i < newLimit; i++)
{
byte[] buffer = oldBufferPool.Take();
if (buffer == null)
{
break;
}
newBufferPool.Return(buffer);
newBufferPool.IncrementCount();
}
this.remainingMemory -= oldBufferPool.BufferSize * delta;
bufferPool = newBufferPool;
}