Home » Android » lru

lru

/**
* memory cache
* @author Administrator
*
* /
Public, class, MemoryCacheUtils {
//private, HashMap, mMemoryCache = new, HashMap ();
Private, LruCache, mMemoryCache;
Public, MemoryCacheUtils () {
Long maxMemory = Runtime.getRuntime (.MaxMemory) (); / / each application allocated memory simulator default is 16M
MMemoryCache = new (LruCache (int) (maxMemory/8)) {// set memory 1/8
@Override
Protected, int, sizeOf (String, key, Bitmap, value) {
//int byteCount = value.getByteCount (); the version is incompatible. This method can directly use the pixel wide high product to obtain memory size
Int byteCount = value.getRowBytes () *value.getHeight ();
Return byteCount;
}
};
}
/ * *
* read from memory
* /
Public, Bitmap, getBitmapFromMemory (String, URL) {
//System.out.println ("memory read data" +mMemoryCache.get (URL));
Return mMemoryCache.get (URL);
}
/ * *
* write memory
* /
Public, void, setBitmapToMemory (String, URL, Bitmap, bitmap) {
MMemoryCache.put (URL, bitmap);
}
}

Latest