Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does MemoryStream Copy on construction?

Tags:

c#

When you construct a MemoryStream from a byte array, does the stream make its own copy? If, so is this a performance concern in a high performance scenario, when compared to just reading the bytes from the original array directly?

like image 411
Christopher Pisz Avatar asked Sep 24 '18 14:09

Christopher Pisz


1 Answers

It doesn't seem to be explicitly mentioned in the documentation, but keep in mind that you can use MemoryStream to modify an existing byte[]. That wouldn't make any sense if the byte array was copied.

Referring to .NET Reference Source, no copy is made on the byte array.

like image 66
Luaan Avatar answered Oct 07 '22 22:10

Luaan