/// <summary> /// Initializes a new instance of the <see cref="BufferPool"/> class. /// </summary> /// <param name="initialBufferCount">The number of initial buffers.</param> /// <param name="bufferManager">The buffer manager.</param> public BufferPool(int initialBufferCount, BufferManager bufferManager) { if (initialBufferCount <= 0) throw new ArgumentException("initialBufferCount"); if (bufferManager == null) throw new ArgumentNullException("bufferManager"); _length = 0; _buffers = new List<ArraySegment<byte>>(bufferManager.CheckOut(initialBufferCount)); // must have 1 buffer _chunkSize = _buffers[0].Count; _bufferManager = bufferManager; _disposed = false; }
private void EnsureCapacity(Position position) { if (position.Index >= _buffers.Count) { foreach (ArraySegment <byte> buffer in _bufferManager.CheckOut(position.Index + 1 - _buffers.Count)) { if (buffer.Count != _chunkSize) { throw new Exception("Received a buffer of the wrong size: this shouldn't happen, ever."); } _buffers.Add(buffer); } } }
/// <summary> /// Initializes a new instance of the <see cref="BufferPool"/> class. /// </summary> /// <param name="initialBufferCount">The number of initial buffers.</param> /// <param name="bufferManager">The buffer manager.</param> public BufferPool(int initialBufferCount, BufferManager bufferManager) { if (initialBufferCount <= 0) { throw new ArgumentException("initialBufferCount"); } if (bufferManager == null) { throw new ArgumentNullException("bufferManager"); } _length = 0; _buffers = new List <ArraySegment <byte> >(bufferManager.CheckOut(initialBufferCount)); // must have 1 buffer _chunkSize = _buffers[0].Count; _bufferManager = bufferManager; _disposed = false; }