The Speed of Managed DirectX


It seems that at least once a week I'm answering questions directly regarding the performance of managed code and Managed DirectX in particular. One of the more common questions I hear is some version of "Is it as fast as unmanaged code?"

Obviously, in a general sense, it isn't. Regardless of the quality of the Managed DirectX API, it still has to run through the same DirectX API that the unmanaged code does. There is naturally going to be a slight overhead, but does it have a large negative impact on the majority of applications? Of course it does not. No one is suggesting that one of the top-of-the-line polygon pushing games coming out today (say, Half Life 2 or Doom 3) should be written in Managed DirectX, but that doesn't mean there isn't a whole slew of games that could be. I get to that in a moment.

I'm also asked quite a bit, "Why is it so slow?" Sometimes, the person hasn't even run a managed application. He just assumes it has to be slow. Other times, he might have run numerous various "scenarios" comparing against the unmanaged code (including running the SDK samples from previous versions) and found that in some instances there are large differences.

As mentioned earlier, all the samples in the previous SDK used the dreaded DoEvents loop, which can artificially slow down the application due to allocations and the subsequent large amounts of collections. The fact that most of the samples run with similar frame rates as those for the unmanaged API was a testament to the speed of the API to begin with.

Many of the developers out there today simply don't know how to write managed code that performs well. This point isn't about any shortcoming of the developer, but rather the newness of the API combined with not enough documentation on performance and how to get the best out of the common language runtime (CLR). For the most part, we are all newbies in this area, but things will only get better.

It's not at all dissimilar to the change from assembler to C++ code for games. It all comes down to a simple question: do the benefits outweigh the negatives? Are you willing to sacrifice a small bit of performance for the easier development of managed code? The quicker time to market? The greater security? The easier debugging?

As I touched on earlier, certain games today aren't good fits for writing the main engine in managed code, but plenty of titles are. The top-10 selling PC games a short while ago included two versions of the Sims, Zoo Tycoon (+ expansion), Age of Mythology, Backyard Basketball 2004, and Uru: Ages Beyond Myst, any of which could have been written in managed code.

Anyone who has taken the time to write some code in one of the managed languages usually realizes the benefits pretty quickly.



Beginning 3D Game Programming
Beginning 3D Game Programming
ISBN: 0672326612
EAN: 2147483647
Year: 2003
Pages: 191
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net