OK, that's extreme. But function calls are not cheap and you can't rely on inlining.
Use static functions whenever possible.
Don't call functions through an interface. 30% slower than regular virtual functions!
Accessors and Mutators are my bestest friends in C++,but they have no place in your Java inner loop.
Be wary of JNI functions. In particular: lots of gl.glXX() functions.
#1 楼 · video.android · 2009-06-26 13:33
Step One: Memory Management(30:00分钟前后)
Never allocate memory. Or release it.
-Well,never allocate during gameplay.
-The GC will stop your game for 100~300ms. That's death for
most real-time games.
Revised:Allocate as much as possible up front,don't release things
until you have natural pause time. Invoke the GC manually when
you know it to be safe.
Use DDMS to track allocations.
-Hey, Java allocates memory CONSTANTLY. Ugh!
-Hidden allocations in things like enum.values(),
Class.getClasName(),Iterator,HashMap,Arrays.sort() etc etc etc.
Some of these are not really avoidable.
Step Two: Don't Call Functions
OK, that's extreme. But function calls are not cheap and you can't rely on inlining.
Use static functions whenever possible.
Don't call functions through an interface. 30% slower than regular virtual functions!
Accessors and Mutators are my bestest friends in C++,but they have no place in your Java inner loop.
Be wary of JNI functions. In particular: lots of gl.glXX() functions.
Step One: Memory Management(30:00分钟前后)
Never allocate memory. Or release it. -Well,never allocate during gameplay. -The GC will stop your game for 100~300ms. That's death for most real-time games.
Revised:Allocate as much as possible up front,don't release things until you have natural pause time. Invoke the GC manually when you know it to be safe.
Use DDMS to track allocations. -Hey, Java allocates memory CONSTANTLY. Ugh! -Hidden allocations in things like enum.values(), Class.getClasName(),Iterator,HashMap,Arrays.sort() etc etc etc. Some of these are not really avoidable.