开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜