Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do not believe .NET provides this, but it should be fairly easy to implement your own implementation of <code>System.IO.Stream</code>, that seamlessly switches backing array. Here are the (untested) basics:</p> <pre><code>public class MultiArrayMemoryStream: System.IO.Stream { byte[][] _arrays; long _position; int _arrayNumber; int _posInArray; public MultiArrayMemoryStream(byte[][] arrays){ _arrays = arrays; _position = 0; _arrayNumber = 0; _posInArray = 0; } public override int Read(byte[] buffer, int offset, int count){ int read = 0; while(read&lt;count){ if(_arrayNumber&gt;=_arrays.Length){ return read; } if(count-read &lt;= _arrays[_arrayNumber].Length - _posInArray){ Buffer.BlockCopy(_arrays[_arrayNumber], _posInArray, buffer, offset+read, count-read); _posInArray+=count-read; _position+=count-read; read=count; }else{ Buffer.BlockCopy(_arrays[_arrayNumber], _posInArray, buffer, offset+read, _arrays[_arrayNumber].Length - _posInArray); read+=_arrays[_arrayNumber].Length - _posInArray; _position+=_arrays[_arrayNumber].Length - _posInArray; _arrayNumber++; _posInArray=0; } } return count; } public override long Length{ get { long res = 0; for(int i=0;i&lt;_arrays.Length;i++){ res+=_arrays[i].Length; } return res; } } public override long Position{ get { return _position; } set { throw new NotSupportedException(); } } public override bool CanRead{ get { return true; } } public override bool CanSeek{ get { return false; } } public override bool CanWrite{ get { return false; } } public override void Flush(){ } public override void Seek(long offset, SeekOrigin origin){ throw new NotSupportedException(); } public override void SetLength(long value){ throw new NotSupportedException(); } public override void Write(byte[] buffer, int offset, int count){ throw new NotSupportedException(); } } </code></pre> <p>Another way to workaround the size-limitation of 2^31 bytes is <a href="http://msdn.microsoft.com/en-us/library/13e02eft.aspx" rel="nofollow noreferrer"><code>UnmanagedMemoryStream</code></a> which implements <code>System.IO.Stream</code> on top of an unmanaged memory buffer (which might be as large as the OS supports). Something like this might work (untested):</p> <pre><code>var fileStream = new FileStream("data", FileMode.Open, FileAccess.Read, FileShare.Read, 16 * 1024, FileOptions.SequentialScan); long length = fileStream.Length; IntPtr buffer = Marshal.AllocHGlobal(new IntPtr(length)); var memoryStream = new UnmanagedMemoryStream((byte*) buffer.ToPointer(), length, length, FileAccess.ReadWrite); fileStream.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); // work with the UnmanagedMemoryStream Marshal.FreeHGlobal(buffer); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload