public void Release(NamedMemoryStream stream) { var bufferSize = stream.Length; if (bufferSize == 0) { _emptyBuffers.Add(stream); _logger.DebugFormat("Stream {0} returned empty", stream.Name); } else if (bufferSize < _fullThreshold) { lock (_readLock) { _partialBuffers.Add(stream); } _logger.DebugFormat("Stream {0} returned partially full", stream.Name); } else { lock (_readLock) { _fullBuffers.Add(stream); } _logger.DebugFormat("Stream {0} returned full", stream.Name); } }
public BufferPool(int numBuffers, int initialBufferCapacity, ILog logger) { _fullThreshold = (int)(initialBufferCapacity * 0.9); _logger = logger; _emptyBuffers = new BlockingCollection <NamedMemoryStream>(numBuffers); _partialBuffers = new BlockingCollection <NamedMemoryStream>(numBuffers); _fullBuffers = new BlockingCollection <NamedMemoryStream>(numBuffers); for (var i = 0; i < numBuffers; i++) { var stream = new NamedMemoryStream(initialBufferCapacity); _logger.DebugFormat("Created stream {0}", stream.Name); _emptyBuffers.Add(stream); } }