Best way to use unmanaged buffer as a Byte []? preferably w/o copying from native to managed memory

L

lallous

Hello

I am writing managed c++/c++ native code.

We have soem buffer passed as char* from native, and we want to pass to a
managed MemoryStream object.

Is it possible to have a Byte [] reference that char* and then we set the
Byte[] size?

Or this:
http://msdn2.microsoft.com/en-us/library/tz333b9s(vs.80).aspx
Is the only suggest way?

The reason I look for an alternative is that because I come fron a native
background and copying memory over and over is a concern.
 
A

adebaene

Hello

I am writing managed c++/c++ native code.

We have soem buffer passed as char* from native, and we want to pass to a
managed MemoryStream object.

Use System::IO::UnmanagedMemoryStream.
The reason I look for an alternative is that because I come fron a native
background and copying memory over and over is a concern.

You shouldn't, as long as a profiler hasn't proved that there is
indeed a performance bottleneck (this is true, as well for native as
for managed code).

Arnaud
MVP - VC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top