将本机缓冲区转换为 MemoryStream

发布于 2024-09-30 15:31:39 字数 419 浏览 1 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞清仓 2024-10-07 15:31:39

它允许您将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.

素衣风尘叹 2024-10-07 15:31:39

MemoryStream(out_buf) 不分配内存,也不获取所有权。 GC 将清理它。

MemoryStream(out_buf) does not allocate memory, nor does it take ownership. The GC will clean it up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文