Haywood Jablomey
Haywood Jablomey

Reputation: 1039

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 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!

Upvotes: 2

Views: 534

Answers (2)

Behrooz
Behrooz

Reputation: 1734

You can use a pipe.

Upvotes: 0

Kate Gregory
Kate Gregory

Reputation: 18974

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.

Upvotes: 5

Related Questions