C++.NET Performance against C#

G

Guest

I was wondering what performance advantages (or ramifications for all I know)
might be apparent if you used Managed C++ (MC++ from know on) instead of C#?
I know C# is a pure .NET language since it was made for the .NET Framework,
but because of my code has been migrated from Java, I need to make a few API
calls outside of the CLR. I'm quite new to C#, cause I'm more familiar with
Java and C++, but I would assume that any programmatic functions outside of
the CLR called by something managed would have a few performance issues. Is
my assumtion correct?

I asked a particularly knowledgable person about it and he said its probably
more prudent to use MC++ since you can mix unmanaged and managed code
together.
And FYI: I have already converted my Java code into MC++ (something
acceptable by the compiler anyway) and I have already restarted from the
beginning to convert my Java code to C# and so far, I've seen only the
benefit of the learning curve with C#.

Also, you would think that I would J# for this migration process wouldn't
you? But I've come to the decision that I want to drop Java completely
because of some fundamental syntax and programmatic issues I have with it, so
J# is not an option for me, especially since all of my future projects are
going to C# and/or MC++.
 
W

William DePalo [MVP VC++]

IamZIM! said:
I was wondering what performance advantages (or ramifications for all I
know)
might be apparent if you used Managed C++ (MC++ from know on) instead of
C#?

This kind of question can degenerate in a hurry into "my language is better
than yours" affair.
I know C# is a pure .NET language since it was made for the .NET
Framework,
but because of my code has been migrated from Java, I need to make a few
API
calls outside of the CLR. I'm quite new to C#, cause I'm more familiar
with
Java and C++, but I would assume that any programmatic functions outside
of
the CLR called by something managed would have a few performance issues.
Is
my assumtion correct?

IMO, C# values elegance, simplicity and ease of use over performance. That
is not to say that it is slow. C++ on the other hand exists to allow you to
get as close to the metal and the operating system as possible, complexity
be damned. That is not to say that it can add 2 and 2 faster than C# can.

I know it is not satisfying but the only answer to your question valid in
all situations is "it depends".
I asked a particularly knowledgable person about it and he said its
probably
more prudent to use MC++ since you can mix unmanaged and managed code
together.

This is where the language shines. If you have a need to mix non-trivial
sections of unmanaged code and managed code in an application, or even in a
module, and if you are already familiar with C++ for Win32, it seems like a
no-brainer to go with MC++ (soon to be C++/CLI)

On the other hand, some might see value in going down the C# path and using
MC++ for the places where interoperability is paramount.

The world is full of choices. If you post a _little_ about your application
you _may_ get some suggestions as to how to proceed.

Regards,
Will
 
A

Alon Fliess

William DePalo said:
This kind of question can degenerate in a hurry into "my language is better
than yours" affair.


IMO, C# values elegance, simplicity and ease of use over performance. That
is not to say that it is slow. C++ on the other hand exists to allow you to
get as close to the metal and the operating system as possible, complexity
be damned. That is not to say that it can add 2 and 2 faster than C# can.

I know it is not satisfying but the only answer to your question valid in
all situations is "it depends".


This is where the language shines. If you have a need to mix non-trivial
sections of unmanaged code and managed code in an application, or even in a
module, and if you are already familiar with C++ for Win32, it seems like a
no-brainer to go with MC++ (soon to be C++/CLI)

On the other hand, some might see value in going down the C# path and using
MC++ for the places where interoperability is paramount.

The world is full of choices. If you post a _little_ about your application
you _may_ get some suggestions as to how to proceed.

Regards,
Will

Hi

Native code may perform better in some situations, for example the
port to MC++ of Quake II usually run 15 percent slower then the native
version, however on Centerino it runs 5 percent faster.
There are some reasons that make managed code a little bit slower:
security checks, array boundary checks, just in time compiler, class
loader, garbage collector, to name a few. Sometimes these mechanisms
provide faster execution then native code. For example: allocating
memory using the GC is very fast (the release is where you pay).
Jitter may choose to create a code specific to the target CPU, or it
may inline code for you. Using class loader may result no loading of
types that you don't use. Garbage collector may bring all needed
variable to memory (process working set) or CPU cache and will save
later page faults.
MC++ is very hard to use language; it is somehow a mixture of two
languages in one. The new C++/CLI is much cleaner language. Using
C++/CLI you may choose the kind of mechanism you want or need. You may
use a native code with managed code, or you can use a pure or safe
approach (no native code at all (. In C++/CLI you may choose to use
template or even STL in safe code using only managed type and you will
get better performance.
But, if you are more Java programmer then a C++, and you don't know or
hate those C++ ideas such as copy constructor, overloading equality
operator, header files and CPP files, forward declarations, linking,
global functions, and many other issues, you better use C#. C++/CLI is
for those C++ programmers that know how to use the language, that need
the power of template and the ability to choose generic when it is
right, that feel the need for deterministic finalization, or they are
so used to C++ and they don't want to learn C#.

Alon Fliess
CTO
The Sela Group
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top