示例#1
0
 /// <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;
 }
示例#2
0
 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);
         }
     }
 }
示例#3
0
 /// <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;
 }