Access C ++ source data from managed C ++

I have my own C ++ library that uses a large static buffer (it receives data from the device).

Let's say this buffer is defined as follows:

unsigned char LargeBuffer[1000000];

Now I would like to open parts of this buffer for managed C ++, for example. when 1000 bytes of new data is stored in the library in LargeBuffer[5000], I would like to call back to managed C ++ code by passing a pointer to LargeBuffer[5000]so that managed C ++ can access 1000 bytes of data there (directly, if possible, i.e. without copying data, for maximum performance).

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

+3
source share
2 answers

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

Now, if you want to transfer this data to other .NET languages, you need to copy this data into managed memory structures or use unsafe code in C #

+4
source

Starting with .net 2.0 and the new IJW, you should have access to the buffer directly from the C ++ CLI.

Until you specify "#pragma unmanaged", then the code will be compiled as a form of control, which allows direct access.

+1
source

Source: https://habr.com/ru/post/1726819/


All Articles