Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the UnmanagedMemoryStream for?

Tags:

c#

io

unsafe

Can someone tell me what the UnmanagedMemoryStream class is used for?

I am not able to figure out how and when this class could be useful?

like image 937
HIyer Avatar asked Dec 05 '11 14:12

HIyer


1 Answers

Using the UnmanagedMemoryStream allows you to read an unmanaged stream without copying everything into the managed heap first, therefore it's less memory intensive when dealing with unmanaged streams. This also allows you to get around memory limitations if you are dealing with a lot of data.

Edit: Note that there is a 2GB limitation with MemoryStream, so you have to use the UnmanagedMemoryStream if you exceed this limitation.

like image 91
Richard Anthony Freeman-Hein Avatar answered Oct 19 '22 10:10

Richard Anthony Freeman-Hein