C# Simple, but good enough?

Started by
13 comments, last by Zahlman 19 years, 4 months ago
c# is perfectly for game development, check out my blog for my current c# Project: abi.exdream.com
I'm developing a complete game in 14 days and will post a screenshot every day.

I also wrote Arena Wars: www.ArenaWars.net
People who still think c# is bad for game development might consider using asm instead of c++ because it "might" be faster, which is total bullshit, since all my apps I ever wrote where highly GPU dependant!
Microsoft DirectX MVP. My Blog: abi.exdream.com
Advertisement
Nypyren gave a good quick overview of C#, but I just wanted to add a few things:
Quote:Arrays will perform bounds checking on EVERY item-fetch/store operation. not just when you use the "System.Array" class, but even when you use int[] or float[]. Then I realized the compiler is actually using the System.Array class when you declare an array like that, and essentially using the Array.this[] indexer.

If you turn on optimization, the JITter is smart enough to turn off bounds checking for arrays in simple, properly formed loops, so there is usually no penalty. As you say, if you want to make sure no bounds checking occurs, you can always use C#'s unsafe-code blocks and some pointer arithmetic. On the other hand, if you want to absolutely guarantee that you won't run over your bounds, get an IEnumerator with the collection's GetEnumerator() method, then iterate.

Quote:'unchecked' doesn't affect arrays, though.

Right. The checked and unchecked keywords either affect a block of statements or a single operation. More information here.

Quote:foreach: for ArrayList, at least, your basic 'foreach' loop doesn't cache the size of the collection - it looks it up once per loop iteration.

This is only sort of true. Whenever the compiler can statically determine that the collection in question is a System.Array, there is no performance disadvantage to using foreach over for. If you compare the MSIL, the code that runs through the loop will be identical. For more complex collections like Hashtables, though, you do indeed pay a small performance penalty for using the IEnumerator generated by foreach. More information is here.

Quote:I haven't gotten down to the level of figuring out how much overhead they have for thread-safe operations, but hopefully it's not too much.

I'm not exactly sure what you mean here. If you want your code to be thread-safe, you have to do that yourself; the overhead would depend on how you implemented the code. The GC doesn't automatically make it thread-safe for you.

Quote:C# Type Reflection: the "is" and "as" operators function by comparing a type-handle-integer to the type-handle stored by whatever managed object you're trying to look up. This is the fastest method that I know of for looking up "what type is this?" info.

Reflection is very powerful in C#. You can find out virtually anything about a class, or even modify a class's runtime behavior if you need to. It's possible to transmute any given program into any other program you could with enough reflection and attributes. I haven't looked into security much in this area, but I have to say I'm almost a little worried about the breadth of things that can be done using reflection.
- k2"Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {[email=kkaitan at gmail dot com]e-mail me[/email]} | {excellent webhosting}
Quote:Original post by aaroncox1234
My problem with people saying that C# is slower is that, has it actually been slow for them? It's kinda trendy on these forms to criticize C# and Java for being too slow but I rarely see anyone doing something that would really need that speed difference. I recall that Quake 2 was rewritten in C# by some programming crew and it ran perfectly fine. And C# could obviously be used for more powerful games than Quake 2. Yet very few people could actually program something at the level of Quake 2.


Maybe you were talking about this ? Quake2 .net. I never heard about anyone converting it to C#. Actually the convertion was from C to C++.

Here is the performance info:
Quote:
However, usefulness only matters if the managed application has the performance you require. Running Quake II.NET in the timedemo test indicates the managed version performs about 85% as fast as the native version. The performance of the managed version was acceptable and testers did not notice a difference between the two versions. You can run the timedemo test by doing the following:
Quote:Original post by Scared Eye
I would like to know if C# is any good for game development. I heard that it is alot slower than C\C++. I have also heard that in some cases(I\O) it is faster than C\C++, is this true?
Managed DirectX is suposed to give me the performance of C++ to C# in DirectX apps. If so then there is no reason to choose C++ over C#. I would also like to know any good links to C#/Managed DirectX resources.

THanks for your time.
S-Eye


C# is just as fast as C/C++ (maybe just about 1% slower). But if you are new to programming, I'd recommend you try VB.NET or boo ( http://boo.codehaus.org/ ) in addition to C#. They both run just as fast as C#, but are much easier to learn and use. Plus you will save many hundreds of dollars if you use the SharpDevelop development environment instead of purchasing Visual Studio .NET.

For Managed DirectX, there is a book by Tom Miller, but even though it came out this year it is already out of date. The DirectX team already changed their preferred way for handling events in their sample code. Download the DirectX SDK and check out the samples folder.
If you have to ask whether a given language (even one like Python with a reputation for being really slow and a design philosophy that emphasizes pretty much everything other than speed) is "fast enough" (as opposed to doing the necessary testing), then it is almost certainly fast enough for anything you are likely to need it for in the near future.

This topic is closed to new replies.

Advertisement