开发者

Accessing native C++ data from managed C++

I have an n开发者_如何学Pythonative C++ library which makes use of a large static buffer (it acquires data from a device).

Let's say this buffer is defined like this:

unsigned char LargeBuffer[1000000];

Now I would like to expose parts of this buffer to managed C++, e.g. when 1000 bytes of new data are stored by the library at LargeBuffer[5000] I would like to perform a callback into managed C++ code, passing a pointer to LargeBuffer[5000] so that managed C++ can access the 1000 bytes of data there (directly if possibile, i.e. without copying data, to achieve maximum performance).

What is the best way to let managed C++ code access data in this native array?


Managed C++ can access the unmanaged memory just fine. You can just pass in the pointer and use it in managed c++.

Now, if you want to then pass that data into other .NET languages, you'll need to copy that data over to managed memory structures or use unsafe code in C#


As of .net 2.0 and the new IJW you should be able to access the buffer directly from CLI C++.

As long as you dont specify "#pragma unmanaged" then the code will be compiled as a form of managed which is what allows the direct access.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜