0

I've developed an application in C# that handles TCP/IP connections and after running some diagnostics, I concluded that compiling and runtime can be improved. I decided to rewrite the entire program in C++ since it also runs smoother in a Lunix envrionment.

Is there a way I can use C# libraries like Sockets, Net, and Net.IPAddress in C++?.

I did some research on this and found out I can call these libraries in C++ through: #using (shevron)System.dll> But I'm hesistant if it will cause overhead and problems in a Lunix envrionment.

12
  • 2
    If you are concerned about your code's portability (to Linux) and it's performance, you need to rewrite your code in C++. Using same old C# code with some additional libraries in C++ will not help. Also just writing your code in C++ will not automatically make it cross-platform Commented Oct 23, 2015 at 15:20
  • 2
    "Lunix"? Do you mean "Linux"? Microsoft's C++ language extension C++/CLI is deisgned for .Net interoperability, but pretty sure this does not work on mono Does Mono .NET support and compile C++ / CLI? Commented Oct 23, 2015 at 15:20
  • 3
    Possible duplicate of Using C# dll in C++ code Commented Oct 23, 2015 at 15:24
  • 2
    You don't have to worry about "overhead and problems", your program will simply never run on Linux or any other Unix flavor. This flavor of C++ interop is only available on Windows. Commented Oct 23, 2015 at 15:24
  • 2
    The #using directive is a C++/CLI feature. Commented Oct 23, 2015 at 15:41

1 Answer 1

1

As I said in my comment, there is Mono documentation about using C# libraries from native code, cf. the link in the comment, http://www.mono-project.com/docs/advanced/embedding/. The native program basically embeds the Mono runtime for that.

Hans Passant made the valid objection that the #using directive in your C++ code indicates that your "C++" code is actually the Microsoft proprietary C++/CLI which will not compile under Linux. How much work it would be to port that depends strongly on how many non-C++ features you used. The interop with Mono will also be more complicated than calling the C# functions in the Microsoft ecosystem.

If you look at performance my gut feeling is that the performance of network-heavy code will be dominated by the networking. Wasting a few CPU cycles should not be an issue, unless you are targeting an embedded system. On a PC, running in Mono or native may not make much of a difference. But this also depends a lot on the actual application (more communication or more computation?).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.