2010-11-04 25 views
4

在我的C++ \ CLI我有這段代碼:轉換本地緩衝區的MemoryStream

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的所有權?

if MemoryStream does does allocate memory again,there's way to convert native buffer to MemoryStream

回答

3

它允許您將out_buf(即它不分配新緩衝區)視爲流,因此您無需擔心分配的另一個緩衝區。

2

MemoryStream(out_buf)不分配內存,也不佔用所有權。 GC將清理它。