将本机缓冲区转换为 MemoryStream
在我的 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)
中,内存流是再次分配内存还是仅获取 out_buf
的所有权?
如果MemoryStream
再次分配内存,有没有办法将本机缓冲区转换为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
does allocate memory again, is there way to convert native buffer to MemoryStream
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它允许您将out_buf(即,它不分配新的缓冲区)视为流,因此您无需担心分配另一个缓冲区。
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) 不分配内存,也不获取所有权。 GC 将清理它。
MemoryStream(out_buf) does not allocate memory, nor does it take ownership. The GC will clean it up.