Search code examples
c#c++unmanaged

Unmanaged C# versus C++


I am a wanna-be Games Developer and I prefer using C#. When I asked what the disadvantages of writing real-time applications in C# were I got 1 significant point back: Garbage Collection and the unpredictable impact it can have on performance.

My counter question is, what about Unmanaged C#? How does it compare (performance-wise) to C++? Is it a valid option for developing software?

I don't hear much about unmanaged c# and all the "unmanaged c# versus C++" questions I saw were unanswered or answered inaccurately. These questions were not on stack overflow.

EDIT:

I believe umanaged C# is "Unsafe Code".


Solution

  • Unsafe code in C# is not for developing separate applications. You can use unsafe code for some kind of time-critical operations, but generally it's not the most effective and the most convenient way of doing this. IMHO, it is primarily designed to give C# an opportunity to integrate with unmanaged dynamic link libraries and unmanaged code, so from my point of view the primary reason is INTEGRATION.

    I can see 3 common ways of managed and unmanaged code integration:

    1. Unsafe code in C# and P/Invoke. Build C# wrappers over compiled unmanaged DLLs.
    2. Managed C++. Build managed assemblies over existing C/C++ code.
    3. COM interoperation. Call Runtime Callable Wrapper from .NET client or call COM Callable Wrapper from COM client.

    On the other hand, it's your architectural and conceptual decision: if you need a full memory and performance control, you develop in C++ or even pure C. If you need advantages and simplicity of modern language and modern technologies, you develop in .NET C#. Or you can use both, and how to integrate them is described above.