public override byte[] TakeBuffer(int bufferSize) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.FindPool(bufferSize); if (bufferPool == null) { if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace)) { TraceCore.BufferPoolAllocation(Fx.Trace, bufferSize); } return(Fx.AllocateByteArray(bufferSize)); } byte[] array = bufferPool.Take(); if (array != null) { bufferPool.DecrementCount(); return(array); } if (bufferPool.Peak == bufferPool.Limit) { bufferPool.Misses++; if (++this.totalMisses >= 8) { this.TuneQuotas(); } } if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace)) { TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize); } return(Fx.AllocateByteArray(bufferPool.BufferSize)); }
private void ChangeQuota(ref InternalBufferManager.PooledBufferManager.BufferPool bufferPool, int delta) { if (TraceCore.BufferPoolChangeQuotaIsEnabled(Fx.Trace)) { TraceCore.BufferPoolChangeQuota(Fx.Trace, bufferPool.BufferSize, delta); } InternalBufferManager.PooledBufferManager.BufferPool bufferPool2 = bufferPool; int num = bufferPool2.Limit + delta; InternalBufferManager.PooledBufferManager.BufferPool bufferPool3 = InternalBufferManager.PooledBufferManager.BufferPool.CreatePool(bufferPool2.BufferSize, num); for (int i = 0; i < num; i++) { byte[] array = bufferPool2.Take(); if (array == null) { break; } bufferPool3.Return(array); bufferPool3.IncrementCount(); } this.remainingMemory -= (long)(bufferPool2.BufferSize * delta); bufferPool = bufferPool3; }