I develop serious games/simulations at my job and we use C++ exclusively, and any loss of performance would put us below our minimum requirements for framerate, etc. However, I plan on downloading the new XNA software and learning C#. Since hardware can make up for some performance loss in the future, and for some smaller applications it would be great to reduce dev time and the number of lines of code when performance is not as important. At some point the total cost of developing an application is offset by the performance gain you would get with using C++, if C# is really as easy as I have read about.
Jeff
Wright State University
Hi Jeff,
As some one who is a partner in a company (and lead developer) that produces enterprise high performance security applications, many of them in C#, I think you will be very surprised what you can do with C#. I develop in C++, C++/CLI (.net C++) and C#. C# is my favorite by far. While it certainly takes a lot of care and research to get the "barn burning" speed you can truly get out of C#. Once you know what to avoid and how to write performance critical apps in C#, you will only go back when you have to... Enjoy learning C#, and be sure to grab the "CLR in C#" books by MS press. It will "show you the light" as far as the inner workings of the CLR and how to make your managed code nearly as fast (and in some cases faster) then it's unmanaged counter parts. It certainly helped my apps go from pretty fast to very fast... You already mentioned the "time to market" benefits of the .Net platform so I will simply agree with you and leave it at that.
God Bless,
I think people underestimate the performance of managed code. There are not many scenarios where unmanaged code will significantly out perform managed code.
When people start to better understand how the garbage collector works and ensure that objects stay small and prevent them from getting promoted to generation 1 and 2 it will make a big performance increase. From what I understand the GC on 360 is the same as in the compact framework, so I¡¯ll have to read up on the differences.
If you look at malloc vs the new keyword in managed code, the new keywords is very fast. The new keyword in managed code is only half the speed of a stack alloc. To beat this performance in C++ you have to override the new keyword and implement your own heap management. To add to the complexity you must also keep your heap defragmented in C++ or else your application will hurt seriously in performance over time.
Many people implement in C++ what the GC already does for you, I¡¯m not saying the GC in managed code is perfect, but it¡¯s pretty darn impressive.
Also, binaries in C++ must be compiled for a target CPU architecture to ensure that the binary is optimized for your current CPU. MSIL is not tied to a specific CPU architecture, and it will be optimized during JITing for your current CPU. Overtime I expect managed code to outperform unmanaged code do to these issues.
You also got to look at where the time is spent in your code, most of it is GFX / IO related and this will not benefit much from being written in C++ since it will still use a HAL.
Inline asm in C++ can potentially beat anything out there, but again, it still does not talk directly to hardware (unless you are writing a driver). And having to keep up with all the new instruction sets being release from the different CPU vendors is going to be harder and harder. A team just working on optimizing the JITer for different CPUs will have the edge in this race I think.
Also, whenever a new version of the JITer is released your code will automatically benefit from it. In C++ you will have to go and recompile your code, and change all your inline asm.
I think the final blow to unmanaged code is time to market. Most people are more productive in managed code vs. unmanaged code. You can also have entry level developers write high performing code, which means less cost for the project.
The tools for managed code are also getting better and better, which again leads to less error prone code and shorter development cycles.
I think most game studios can live with a 20% performance decrease if they can get their product out faster at less cost.
Sorry for the long post J
Roger Larsen
Jim,
You are correct, 20% is probably the worst I have seen. Unless you do some real thight loop memory operations.
Most people never talk about poorly written code either, which is slow regardless of programming language. There is some horribly inefficent examples for every language out there. Having said that, I find it a lot harder to optimize c++ for performance, than c#. The guts is in the algorithms, if you get them right it should not really matter if you write your code managed c#.
Roger Larsen
From my experience (and that is having developed several shareware games) C# is no different than Managed C++. The same performance. Native C++ only has a small (within 1%) performace increase over C#. I have been successful in porting one of my games from CLI C# to MONO C# for linux/Mac OS X and it was flawless.
C# IS the future, it's easier to read, easier to program, opens up the doors to RAD C++ because that's what C# is.
What Roger said about the algorithms is true, after all the language comparisons, if its just poor code, it's poor code.
QuantumMischief wrote:
Since XNA is using C#, and is is a more intuitive language than C++, is it possible that in the future that C# will dominate, espessially in AAA titles. Could XNA be ushering a new way of programming in the main stream
Although I¡¯m a huge C++ fan but..
XNA will be using C#, DirectX is now shipped with many samples tutorials for managed frame work, and the bench mark between C++VS C# graphic applications isn¡¯t noticeable even sometimes its better on C# with all that I guess its time to migrate from C++ to C#...
QuantumMischief wrote:
Since XNA is using C#, and is is a more intuitive language than C++, is it possible that in the future that C# will dominate, espessially in AAA titles. Could XNA be ushering a new way of programming in the main stream
I think, before XNA released,C# isn't the primary gaming language
but,since XNA will be released, it's said that in the FAQ,C# will be the important gaming language.
hehe
Hi there,
I don't know if this is the right forum for this but I was reading this thread and had a question.
I haven't done hobby PC game programming or C/C++ coding since the early 90s. I started to get back into C/C++ game programming by looking at the GBA (I went back to my roots and have been coding in 6502ASM). Just when I was about to get started I read the news on XNA. I've read a few things on C# and CLR. I've read that managed code can run as fast if not faster than unmanaged code.
Anyway, back when I did game programming, it was better to write code like 320 * x as (x << 8) + (x << 6). Do you still need to do optimizations like this if the number can be represented as a power of2 Have the compilers (more importantly C#) gotten better to where this type of optimization is not needed