我推荐这本书:Mario Zechner和Robert Green撰写的《 Beginning Android 4 Games Development》,适合从事Android游戏的初学者。
该书在第192页指出:
Method calls have a larger associated cost in Dalvik than in other VMs. Use static methods if you can, as those perform best. Static methods are generally regarded as evil, much like static variables, as they promote bad design, so try to keep your design as clean as possible. Perhaps you should avoid getters and setters as well. Direct field access is about three times faster than method invocations without the JIT, and about seven times faster with the JIT. Nevertheless, think of your design before removing all your getters and setters.
现在,这是否对当今产生了巨大的影响?性能和设计之间真正的最佳选择是什么?因为如果im具有静态变量和方法,它将在RAM中直到应用程序终止,如果我的应用程序太大而android 2.3将成为市场的一部分,那就不好了。
在Android供电的设备上进行开发时,性能是要考虑的重要因素,因为我们还需要考虑配置较低的设备。
就静态变量和方法的使用而言,它完全取决于应用程序所针对的特定设备。
您是绝对正确的-静态变量和方法将驻留在RAM中,直到应用程序终止,但是如果您的android设备配备了1GB以上的RAM,并且如果您的目标是2.3,则请相信我,这不是问题将会有很多ANR,因为各种对象所需的内存将无法自由使用。
最适合您的选择是:
开发后:检查您的应用程序正在使用多少内存每个基于Android的设备对系统可用的RAM数量有所不同,因此为每个应用程序提供了不同的堆限制。
您可以调用getMemoryClass()来获取应用程序可用堆的估计值(以兆字节为单位)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句