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 MemoryStream(out_buf)
, does memory stream allocate memory again or just take ownership of the out_buf
?
if MemoryStream
开发者_StackOverflowdoes allocate memory again, is there way to convert native buffer to MemoryStream
?
It allows you to treat out_buf
(i.e., it does not allocate a new buffer) as a stream, so you have nothing to worry about another buffer being allocated.
MemoryStream(out_buf) does not allocate memory, nor does it take ownership. The GC will clean it up.
精彩评论