Question
So I have a server in c# and im trying to optomize it in general
https://www.quora.com/How-do-I-call-a-C-function-from-C-code
So I saw that I can call function wrote in c++ in a c# project
so is it worth to rewetie the functions in c++ and call them in c# ?
also If i did that running the server in linux will stay the same using
dotnet run command or I have to do extra things ?
Thanks,
Quora
How do I call a C++ function from C# code?
Answer (1 of 5): To call a C++ function from C# code, you can use Platform Invoke (P/Invoke). Platform Invoke is a feature of .NET that allows managed code to call unmanaged code, such as C++ code.
Here are the general steps to call a C++ function from C# code using P/Invoke:
1. Define the C++ ...
2 Replies
No.
This isn't python, C# isn't slow
In fact, C# is sometimes faster than C or C++ (because of the JIT compiler and hot path optimizations)
If you have profiled some code and found that GC/allocations are causing performance issues, then you might be able to get some performance gains by rewriting that particular piece of code in C/C++/Rust etc and using C-FFI to call it from C#
but as a general concept, you don't gain anything from rewriting a function from C# to C++
you gain bugs
and the overhead of now having to read/write an additional language to maintain your project