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));
}
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);
私が所有している 2 つの Android フォンのどちらにもデフォルトでプロパティが設定されていないため、デフォルト値16m
はおそらく重要です。dalvik.vm.heapsize