如何在您的Android应用中利用超过512MB的RAM?

huangapple go评论56阅读模式
英文:

How to utilize more than 512MB of RAM in your android app?

问题

我正在开发一个仅在一组有6GB RAM的设备上使用的应用程序。目前,我的应用程序在接近512MB的时候表现不佳。我想要能够利用更多RAM(约1GB),因为我知道分配给用户的设备只用于使用这个应用程序,因此这个应用程序占用大部分设备RAM不是问题此设备不可用Google Play服务,也没有浏览器)。

该应用程序同时执行各种重型操作,同时不断更新UI,因此必然会超过512MB。到目前为止,我已经设法将所有内容控制在480MB以下,但考虑到我今天开始实施的即将推出的功能计划,我认为应用程序不得不使用更多的RAM是不可避免的。

请就如何利用更多RAM提供建议。我尚未找到任何好的答案。

我尝试过设置android:largeHeap="true",但似乎不起作用。还查看了与此相关的帖子,但在我看来没有提供最佳解决方案。

英文:

I am working on an app that will be exclusively used on a limited set of devices, all of which have 6GB of RAM. Currently my app is misbehaving as it touches the 512MB mark. I want to be able to utilize more RAM (~1GB) because I know the devices allocated to users are for one purpose only and that is to use this app so it is not an issue that this app is taking majority of the device RAM.(Google play services are not available in this device and there is no browser either)

The app is doing a wide variety of heavy operations simultaneously while also continuously updating UI so it is bound to cross the 512MB. I have so far managed to keep it all under 480MB but with the plan of upcoming features that I have start implementing today, I think it is inevitable that the app will have to use more RAM.

Please advise on how to utilize more RAM. I have not been able to find any good answer to this

I have tried setting android:largeHeap="true" but that doesn't seem to do to the trick.
Also checked out this relevant post about this but it hasn't provided the best solution in my opinion.

答案1

得分: 2

请建议如何更充分利用更多的RAM

您可以:

  • 将您的应用程序拆分为多个进程。每个进程的虚拟机(VM)可以使用最大堆限制。您将受限于在两个进程之间使用进程间通信(IPC),如绑定服务。
  • 将一些占用大量RAM的逻辑移到C/C++中。本机内存分配(malloc()和基于它构建的内容)不受VM的堆限制。
  • 更加专注于优化内存使用,以便适应堆限制内。

我知道分配给用户的设备只用于一个目的,那就是使用这个应用程序,所以这个应用程序占用大部分设备的RAM并不是一个问题

如果这台设备有自定义固件,您可以在固件中提高堆限制。

英文:

> Please advise on how to utilize more RAM

You could:

  • Split your app into multiple processes. Each process' VM can use up to the heap limit. You will be limited to using inter-process communication (IPC) between the two processes, such as bound services.
  • Move some of your heavy-RAM logic to C/C++. Native memory allocations (malloc() and things built atop it) are not subject to the heap limit of the VM.
  • Focus more on optimizing your memory use, such that you can fit within your heap limit.

> I know the devices allocated to users are for one purpose only and that is to use this app so it is not an issue that this app is taking majority of the device RAM

If this device has custom firmware, you could raise the heap limit in the firmware.

huangapple
  • 本文由 发表于 2023年2月16日 18:28:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定