public override void Clear() { for (int i = 0; i < (int)this.bufferPools.Length; i++) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.bufferPools[i]; bufferPool.Clear(); } }
private void TuneQuotas() { if (!this.areQuotasBeingTuned) { bool flag = false; try { Monitor.TryEnter(this.tuningLock, ref flag); if (!flag || this.areQuotasBeingTuned) { return; } else { this.areQuotasBeingTuned = true; } } finally { if (flag) { Monitor.Exit(this.tuningLock); } } int num = this.FindMostStarvedPool(); if (num >= 0) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.bufferPools[num]; if (this.remainingMemory < (long)bufferPool.BufferSize) { int num1 = this.FindMostExcessivePool(); if (num1 >= 0) { this.DecreaseQuota(ref this.bufferPools[num1]); } } if (this.remainingMemory >= (long)bufferPool.BufferSize) { this.IncreaseQuota(ref this.bufferPools[num]); } } for (int i = 0; i < (int)this.bufferPools.Length; i++) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool1 = this.bufferPools[i]; bufferPool1.Misses = 0; } this.totalMisses = 0; this.areQuotasBeingTuned = false; return; } else { return; } }
public override void ReturnBuffer(byte[] buffer) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.FindPool((int)buffer.Length); if (bufferPool != null) { if ((int)buffer.Length == bufferPool.BufferSize) { if (bufferPool.Return(buffer)) { bufferPool.IncrementCount(); } } else { throw Fx.Exception.Argument("buffer", InternalSR.BufferIsNotRightSizeForBufferManager); } } }
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)); } else { byte[] numArray = bufferPool.Take(); if (numArray == null) { if (bufferPool.Peak == bufferPool.Limit) { InternalBufferManager.PooledBufferManager.BufferPool misses = bufferPool; misses.Misses = misses.Misses + 1; InternalBufferManager.PooledBufferManager pooledBufferManager = this; int num = pooledBufferManager.totalMisses + 1; int num1 = num; pooledBufferManager.totalMisses = num; if (num1 >= 8) { this.TuneQuotas(); } } if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace)) { TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize); } return(Fx.AllocateByteArray(bufferPool.BufferSize)); } else { bufferPool.DecrementCount(); return(numArray); } } }
private int FindMostStarvedPool() { long num = (long)0; int num1 = -1; for (int i = 0; i < (int)this.bufferPools.Length; i++) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.bufferPools[i]; if (bufferPool.Peak == bufferPool.Limit) { long misses = (long)bufferPool.Misses * (long)bufferPool.BufferSize; if (misses > num) { num1 = i; num = misses; } } } return(num1); }
private int FindMostExcessivePool() { long num = (long)0; int num1 = -1; for (int i = 0; i < (int)this.bufferPools.Length; i++) { InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.bufferPools[i]; if (bufferPool.Peak < bufferPool.Limit) { long limit = (long)(bufferPool.Limit - bufferPool.Peak) * (long)bufferPool.BufferSize; if (limit > num) { num1 = i; num = limit; } } } return(num1); }
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 bufferPool1 = bufferPool; int limit = bufferPool1.Limit + delta; InternalBufferManager.PooledBufferManager.BufferPool bufferPool2 = InternalBufferManager.PooledBufferManager.BufferPool.CreatePool(bufferPool1.BufferSize, limit); for (int i = 0; i < limit; i++) { byte[] numArray = bufferPool1.Take(); if (numArray == null) { break; } bufferPool2.Return(numArray); bufferPool2.IncrementCount(); } InternalBufferManager.PooledBufferManager bufferSize = this; bufferSize.remainingMemory = bufferSize.remainingMemory - (long)(bufferPool1.BufferSize * delta); bufferPool = bufferPool2; }
private void IncreaseQuota(ref InternalBufferManager.PooledBufferManager.BufferPool bufferPool) { this.ChangeQuota(ref bufferPool, 1); }