Sunday, August 2, 2009

Why is C/C++ so much better for game programming than other langues, like Java?

Just curious really.

Why is C/C++ so much better for game programming than other langues, like Java?
C and C++ compiles into machine code of the processor on which the program was compiled. This means that the game can communicate directly with the processor in the closest way possible, ensuring that as much resources as possible go towards running the game and not wasting any resources on other stuff. C/C++ also requires more low-level operations, like talking directly with the graphic drivers and/or graphics subsystem of the operating system.





Java, on the other hand, while very optimized in the latest versions (5 and 6) does not compile into machine code, but into a Java-specific byte code that something called a Java Virtual Machine (JVM for short) understands. This byte code is platform independent, meaning that it is not tied to a specific processor or operating system, but it also means that when the application (game) is run, the JVM needs to translate the byte code into the machine code on which the program is being run. This causes overhead and a waste of resources that often cannot be wasted when making games. Also, Java is a very high-level language, and does not provide direct access to the low level layers of the OS, like the graphics driver and the graphical subsystem of the OS. This means that you cannot as efficiently work with graphics.
Reply:If such speed is critical from java code, you can compile to native -- JNI -- and bypass the JRE. You are then on that platform's limitations at that point and will need to write a program in C to launch.





There is much tweaking required with C++ / C and that means at the source code level before you find a suitable platform for compile.





And, depends on your definition of game programming. If you're just programming the graphics card for xx platform, OpenGL is the better choice over C++. If you want to construct a virtual world for an immersion helmet, java looks pretty good from a productivity standpoint.
Reply:Java runs in a sandboxed virtual machine and doesn't have the same level of access to the graphics hardware that a native program does.
Reply:I'm not a real big programmer, but I remember reading somewhere that C/C++ require a lot less strings of information to get what you want done. It's a lot more customizable. I'm not 100% sure really but I know it was something really big :P.

love song

No comments:

Post a Comment