Using a C/C++ data structure in a C# program
I have a super high-performance C/C++ data structure (see here!) that I'd like to access and use in my C# program.
Imagine the开发者_StackOverflow中文版 C/C++ data structure has a public API (get
, add
, delete
, etc). How can I call these methods lots of times within C# in a high-performance way?
P.S. Before you criticize my use of the phrase "C/C++"...
In my view, C/C++ is distinct from both the C and C++ programming languages. I don't know C++, but rather an extension to C that uses some C++ constructs and can be compiled with a C++ compiler!If performance is important to you, then you should avoid crossing the managed/unmanaged boundary "lots of times". Both C# and C++ can be high performance languages but the interop perf costs are not pleasant.
I suggest you write a C library (which could be implemented with C++ constructs as long as the methods are extern C) and call it from the C# code -once!- using P/Invoke. This library can party on your high performance data structure and return some useful information to the C# side.
You can use a pipe.
精彩评论