J2ME游戏代码设计tips11条

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Coding Tips

The following tips are only suggestions and may or may not give gains in performance, it

is to your own judgment and discretion to use them or not.

1. Use StringBuffer instead of String because of the fact the String object can not

be changed. Any modification to a String variable is actually a new object

creation.

2. Accessing class variables directly is faster then using setter and getter

methods

3. Using local variables are more efficient then instance/class variables

4. Using variables are more efficient then arrays.

5. Avoid synchronization in loops because there is an extra over head to lock and

unlock each time the loop occurs

6. Counting down in loops is faster then counting up

7. Use compound operators like x += 1 instead o f x = x + 1 because fewer byte

codes is generated

8. Remove constant calculations in loops

9. Reuse objects

10. Assign null to unused objects, especially unused threads

11. Try to use already built in methods, for example if you want to copy data from

one array to another use System.arraycopy more then likely this method will

be more efficient then the one you created yourself

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航