多少内存每一个Android程序得到什么呢?什么呢、内存、程序、Android

2023-09-13 01:52:04 作者:倪的温柔、只许珴拥有

我们可以依靠我们的Andr​​oid应用程序得到的内存一组量还是它的手机型号和操作系统版本之间有什么不同?

Can we rely on our Android app getting a set amount of memory or does it vary between phone models or OS versions?

例如,我有一个内存缓存,我已经将其限制设置为5 MB。如果一台设备上,我的应用程序将只得到8 MB的内存玩,而在另一个,24 MB,我想调整的内存缓存采取更多或更少的内存优势的上限。

For example, I have a memory cache, and I've set its limit to 5 MB. If on one device, my app will only get 8 MB of memory to play with, and on another, 24 MB, I'd like to tune the cap of the memory cache to take advantage of more or less memory.

有什么办法算出这个,确实量甚至有所不同?

Is there any way to figure this out, does the amount even vary?

推荐答案

是的,最大堆大小各不相同,从设备到设备。你可以通过调用getMemoryClass().

Yes, the maximum heap size varies from device to device. You can check the device's approximate per-application memory class by calling getMemoryClass().

返回当前设备的近似每个应用程序的内存类。这给了你,你应该如何努力内存限制强加给你的应用程序,让整个系统的工作最好的一个想法。返回的值以MB为单位;基线Android的内存类是16(这恰好是这些设备的Java堆限制);某些设备具有更多的内存可能会返回24,甚至更高的数字。

Returns the approximate per-application memory class of the current device. This gives you an idea of how hard a memory limit you should impose on your application to let the overall system work best. The returned value is in megabytes; the baseline Android memory class is 16 (which happens to be the Java heap limit of those devices); some device with more memory may return 24 or even higher numbers.

唯一内建的方式来改变一个应用程序的堆大小是通过设置安卓largeHeap =真正的的Andr​​oidManifest.xml 。这通常会增加堆的大小从48到128。请记住这种方法只能在3.X平板电脑。否则,你需要一个根深蒂固的设备,这显然不是你想依靠作为一个开发者。

The only built-in way to change heap size of an app is by setting android:largeHeap="true" in the AndroidManifest.xml. This will generally increase heap size from 48 to 128. Keep in mind this approach will only work on 3.x tablets. Otherwise, you'll need a rooted device, which is obviously not something you would want to rely on as a developer.