Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing native C++ data from managed C++

I have an native 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?

like image 385
Enrico Detoma Avatar asked Jul 24 '26 06:07

Enrico Detoma


1 Answers

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#

like image 107
Joe Doyle Avatar answered Jul 25 '26 20:07

Joe Doyle