Convert Native Buffer to MemoryStream

In my C ++ \ CLI, I have this piece of code:

array<Byte>^ out_buf = gcnew array<Byte>(stream_size); Marshal::Copy(IntPtr(buf), out_buf, 0, Int32(stream_size)); System::IO::MemoryStream^ stream = gcnew MemoryStream(out_buf); 

in a MemoryStream(out_buf) , does the memory stream allocate memory again or just go into the out_buf property?

if a MemoryStream allocates memory again, is there a way to convert my own buffer into a MemoryStream ?

+4
source share
2 answers

It allows you to handle out_buf (i.e., not allocate a new buffer) as a stream, so you have nothing to worry about when another buffer is allocated.

+3
source

MemoryStream (out_buf) does not allocate memory or receive ownership. GC will clear it.

+2
source

All Articles