Quantcast
Channel: magick Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1011

Commented Unassigned: Avoid (Memory)Stream to byte array conversion where possible [1381]

$
0
0
Provide a 'fast' constructor for MemoryStream and avoid the expensive StreamHelper.ToByteArray call.

With the MemoryStream you can save 50% of the managed memory usage if you don't copy the byte-buffer.

Something like that:
```
public void Read(Stream stream, MagickReadSettings readSettings)
{
Throw.IfNull("stream", stream);

if( stream.GetType() != typeof(System.IO.MemoryStream) )
{
this.Read(StreamHelper.ToByteArray(stream), readSettings);
return;
}

byte[] data = MemoryStream.GetBuffer();
int length = MemoryStream.Length;

this.Read(data, length, readSettings);
}
```

So people are able to use some kind of buffer pooling or else without the penalty of creating byte arrays only for the Read() call.
Comments: Thanks for the suggestion. But I think there is an easier solution. I now do a call to ToArray inside the StreamHelper.ToByteArray method but I could change this to GetBuffer instead. Feel free to submit a pull request for this on github.

Viewing all articles
Browse latest Browse all 1011

Trending Articles