Joe said:
Here's another .NET Show where Nick Hodapp demos a version of Quake
II that was written with C#:
http://msdn.microsoft.com/theshow/Episode035/default.asp
Not quite <g>
The Quake demo was written in C++ ported from C and then compiled as Managed
C++ using the /clr switch.
"NICK HODDAP [sic]: So what I have here, we're going to run the native
version
first, the native version of Quake. So this is really just the source code
that you could download off of idSoftware, and Vertigo is hosting this out
on their website so you can download this and build it yourself. The one
thing that they did in addition to just rebuilding it for .NET and the CLR
is they ported it from strictly a C-based application to C++. And the reason
they did that - it didn't involve a whole lot of work - was because in order
to enable that feature of the compiler that allows you to recompile for
Managed, it has to be in C++ syntax. And so there are only a few minor
differences: C++ is really a superset of C, but you can do things in C that
break that transition. So they fixed that up. So what we're looking at here
is the native version, and we can drop into a mode that allows us to see the
frame rate that we're getting. "
However, there is a bigger story here. The language is just the input to the
compiler, its largely irrelevant (largely, but not completely). What's
important is that the output of the compiler is IL. Now bear in mind that
guys from the VC team wrote the JIT compiler so all the experience from
years of writing C++ optimization code has gone into the JIT compiler. So
once the IL has been JITted (that's the caveat) the native code created by
the JIT compiler will run as fast as native code produced by the native C++
compiler. (Actually, my tests have shown that for some optimization
switches, managed C++ can run faster than native C++).
The demo shows that the managed Quake (ie compiled with /clr) runs at 50
frames/sec and the native version (same code without /clr) runs at 60
frames/sec. I haven't looked the code so I cannot conclusively identify why
this is the case, but I suspect there's some marshalling betweem managed and
unmanaged types for calls to the Win32 API, and I suspect the optimization
swiches used are not the most optimal for managed C++ <g>. Note that the
graphics don't use WinForms.
BTW Nick Hodapp mentions that with some tweaking of the Quake code you can
get to 100% the performance of the native version, and I believe him.
Richard