Max*_*mus 18 android android-ndk
NDK下载页面指出,"NDK的典型优秀候选者是独立的,CPU密集型操作,不会分配太多内存,例如信号处理,物理模拟等."
我来自C背景,并很高兴尝试使用NDK来操作我的大部分OpenGL ES函数和任何与物理,顶点动画等相关的本机函数......我发现我依赖于它点击原生代码,想知道我是否犯了一些错误.我在这一点上测试时没有遇到任何麻烦,但我很好奇我将来是否会遇到问题.
例如,我定义了游戏结构(有点像在San-Angeles示例中看到的).我正在动态加载对象的顶点信息(正好是活动游戏区所需要的),因此顶点,法线,纹理坐标,索引和纹理图形数据都会发生相当多的内存分配...只是为了命名要点.我非常小心释放游戏区域之间的分配.
我是否会更安全地设置阵列大小的上限或者我现在应该勇敢地向前冲锋?
Tim*_*ger 10
由于使用NDK的应用程序应该与使用SDK开发的应用程序类似,我认为合理堆使用的最佳指导来自ActivityManager.java的注释.
/**
* Return 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.
*/
public int getMemoryClass() {
return staticGetMemoryClass();
}
/** @hide */
static public int staticGetMemoryClass() {
// Really brain dead right now -- just take this from the configured
// vm heap size, and assume it is in megabytes and thus ends with "m".
String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
}
Run Code Online (Sandbox Code Playgroud)
设置Dalvik VM的堆大小的代码位于AndroidRuntime.cpp中,并提供了如何使用property_get函数确定本机代码中堆分配的粗略限制的示例.
strcpy(heapsizeOptsBuf, "-Xmx");
property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
//LOGI("Heap size: %s", heapsizeOptsBuf);
opt.optionString = heapsizeOptsBuf;
mOptions.add(opt);
Run Code Online (Sandbox Code Playgroud)
默认值16m很可能很重要,因为我拥有的两部Android手机都没有dalvik.vm.heapsize默认设置的属性.
| 归档时间: |
|
| 查看次数: |
9115 次 |
| 最近记录: |