public ClusteredMemoryStream(ClusteredArray <byte> buffer) { _buffer = new ClusteredArray <byte>(buffer.LengthThreshold, buffer.Length); ClusteredArray <byte> .Copy(buffer, 0, _buffer, 0, buffer.Length); _length = _capacity = buffer.Length; _expandable = true; _writable = true; _exposable = true; _origin = 0; // Must be 0 for byte[]'s created by MemoryStream _isOpen = true; }
// PRIVATE Grows or shrinks the buffer to hold capacity objects. Capacity // must be >= _size. private void SetCapacity(int capacity) { ClusteredArray <T> newarray = new ClusteredArray <T>(capacity); if (_size > 0) { if (_head < _tail) { ClusteredArray <T> .Copy(_array, _head, newarray, 0, _size); } else { ClusteredArray <T> .Copy(_array, _head, newarray, 0, _array.Length - _head); ClusteredArray <T> .Copy(_array, 0, newarray, _array.Length - _head, _tail); } } _array = newarray; _head = 0; _tail = (_size == capacity) ? 0 : _size; _version++; }