我正在尝试遵循有关 LruCache 使用的 2 年历史的 android 教程,到目前为止我在 Google 上搜索过的一些示例具有相同的方法,即传递一个转换为 KiB 的值(int)。
final int maxMemory = (int)(Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8; //use 1/8th of what is available
imageCache = new LruCache<>(cacheSize);
然而,从谷歌的文档中,传递的 int 值似乎被转换为字节(来自 MiB): https ://developer.android.com/reference/android/util/LruCache.html
int cacheSize = 4 * 1024 * 1024; // 4MiB
LruCache<String, Bitmap> bitmapCache = new LruCache<String, Bitmap>(cacheSize) {
protected int sizeOf(String key, Bitmap value) {
return value.getByteCount();
}
}
我想知道哪个是正确的计量单位。任何答案将不胜感激..