如何增加Android应用程序的堆大小? [英] How to increase heap size of an android application?

查看:42
本文介绍了如何增加Android应用程序的堆大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用多个 3D 模型的 Android 应用程序.这种带有纹理的模型会占用大量内存.我发现制造商对应用程序可以使用的堆大小设置了限制.例如我的平板电脑 Samsung Galaxy Tab 8.9 P7310 可以占用 64MB 内存.

I am writing an Android application which uses several 3D models. Such a model with textures can take up a lot of memory. I found out the manufacturer sets a limit on the heap size an application can use. For example my tablet Samsung Galaxy Tab 8.9 P7310 can take up 64MB of memory.

有没有办法增加应用程序可以使用的内存大小?

Is there a way to increase this size of memory an application can use?

推荐答案

您可以使用 android:largeHeap="true" 请求更大的堆大小,但这不适用于任何预蜂窝设备.在 2.3 之前的设备上,您可以使用 VMRuntime 类,但这不适用于 Gingerbread 及更高版本.

You can use android:largeHeap="true" to request a larger heap size, but this will not work on any pre Honeycomb devices. On pre 2.3 devices, you can use the VMRuntime class, but this will not work on Gingerbread and above.

拥有尽可能大的限制的唯一方法是通过 NDK 执行内存密集型任务,因为 NDK 不像 SDK 那样强加内存限制.

The only way to have as large a limit as possible is to do memory intensive tasks via the NDK, as the NDK does not impose memory limits like the SDK.

或者,您可以只加载当前可见的模型部分,并根据需要加载其余部分,同时从内存中删除未使用的部分.但是,这可能无法实现,具体取决于您的应用.

Alternatively, you could only load the part of the model that is currently in view, and load the rest as you need it, while removing the unused parts from memory. However, this may not be possible, depending on your app.

这篇关于如何增加Android应用程序的堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆