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

Edited 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.

Viewing all articles
Browse latest Browse all 1011

Trending Articles