将本地缓冲区转换为内存流。

4
在我的C++/CLI代码中,我有这段代码:

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);

MemoryStream(out_buf)中,MemoryStream会重新分配内存还是只接管out_buf的所有权呢?

如果MemoryStream会重新分配内存,那么有没有办法将本地缓冲区转换为MemoryStream

2个回答

3

它允许你将out_buf视为流(即不分配新缓冲区),因此你不必担心另一个缓冲区被分配。


2

MemoryStream(out_buf)不会分配内存,也不会拥有它。GC会负责清理。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接