English 中文(简体)
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?

最佳回答

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签