public override void ReturnBuffer(byte[] buffer) { BufferPool pool = this.FindPool(buffer.Length); if (pool != null) { if (buffer.Length != pool.BufferSize) { throw Fx.Exception.Argument("buffer", SRCore.BufferIsNotRightSizeForBufferManager); } if (pool.Return(buffer)) { pool.IncrementCount(); } } }
public override void ReturnBuffer(byte[] buffer) { BufferPool bufferPool = FindPool(buffer.Length); if (bufferPool != null) { if (buffer.Length != bufferPool.BufferSize) { throw new ArgumentException("BufferIsNotRightSizeForBufferManager"); } if (bufferPool.Return(buffer)) { bufferPool.IncrementCount(); } } }
public override void ReturnBuffer(byte[] buffer) { Fx.Assert(buffer != null, "caller must verify"); BufferPool bufferPool = FindPool(buffer.Length); if (bufferPool != null) { if (buffer.Length != bufferPool.BufferSize) { throw Fx.Exception.Argument(nameof(buffer), SR.BufferIsNotRightSizeForBufferManager); } if (bufferPool.Return(buffer)) { bufferPool.IncrementCount(); } } }
private void ChangeQuota(ref BufferPool bufferPool, int delta) { BufferPool pool = bufferPool; int limit = pool.Limit + delta; BufferPool pool2 = new BufferPool(pool.BufferSize, limit); for (int i = 0; i < limit; i++) { byte[] buffer = pool.Take(); if (buffer == null) { break; } pool2.Return(buffer); pool2.IncrementCount(); } this.remainingMemory -= pool.BufferSize * delta; bufferPool = pool2; }
private 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; }
public override void ReturnBuffer(T[] buffer) { Trace.Assert(buffer != null, "Return buffer is null"); BufferPool bufferPool = FindPool(buffer.Length); if (bufferPool != null) { if (buffer.Length != bufferPool.BufferSize) { throw new ArgumentException("Buffer Is Not Right Size For Buffer Manager", nameof(buffer)); } if (bufferPool.Return(buffer)) { bufferPool.IncrementCount(); } } }
public override void ReturnBuffer(byte[] buffer) { Fx.Assert(buffer != null, "caller must verify"); #if DEBUG int hash = buffer.GetHashCode(); if (!this.buffersPooled.TryAdd(hash, CaptureStackTrace())) { string originalStack; if (!this.buffersPooled.TryGetValue(hash, out originalStack)) { originalStack = "NULL"; } Fx.Assert( string.Format( CultureInfo.InvariantCulture, "Buffer '{0}' has already been returned to the bufferManager before. Previous CallStack: {1} Current CallStack: {2}", hash, originalStack, CaptureStackTrace())); } #endif //DEBUG BufferPool bufferPool = FindPool(buffer.Length); if (bufferPool != null) { if (buffer.Length != bufferPool.BufferSize) { throw Fx.Exception.Argument("buffer", InternalSR.BufferIsNotRightSizeForBufferManager); } if (bufferPool.Return(buffer)) { bufferPool.IncrementCount(); } } }
private void ChangeQuota(ref BufferPool bufferPool, int delta) { // TODO tracing //if (TraceCore.BufferPoolChangeQuotaIsEnabled(Fx.Trace)) { // TraceCore.BufferPoolChangeQuota(Fx.Trace, bufferPool.BufferSize, delta); //} BufferPool oldBufferPool = bufferPool; int newLimit = oldBufferPool.Limit + delta; BufferPool newBufferPool = BufferPool.CreatePool(oldBufferPool.BufferSize, newLimit); for (int i = 0; i < newLimit; i++) { T[] buffer = oldBufferPool.Take(); if (buffer == null) { break; } newBufferPool.Return(buffer); newBufferPool.IncrementCount(); } _remainingMemoryInBytes -= oldBufferPool.BufferSize * delta; bufferPool = newBufferPool; }
void ChangeQuota(ref BufferPool bufferPool, int delta) { BufferPool oldBufferPool = bufferPool; int newLimit = oldBufferPool.Limit + delta; BufferPool newBufferPool = new BufferPool(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; }