通过 进程信息目录proc,读取文件"/proc/meminfo"的信息能够获取手机Memory的总量,而通过
memInfoReader = new MemInfoReader();
memInfoReader.readMemInfo();
long lFree = memInfoReader.getFreeSize()+ memInfoReader.getCachedSize();
String free = Formatter.formatShortFileSize(getContext(), lFree);
String uesd = Formatter.formatShortFileSize(getContext(),memInfoReader.getTotalSize()-lFree);
"/proc/meminfo"文件记录了android手机的一些内存信息,在命令行窗口里输入"adb shell",进入shell环境,输入"cat /proc/meminfo"即可在命令行里显示meminfo文件的内容,具体如下所示。
C:/Users/Figo>adb shell
# cat /proc/meminfo
cat /proc/meminfo
MemTotal: 94096 kB
MemFree: 1684 kB
Buffers: 16 kB
Cached: 27160 kB
SwapCached: 0 kB
Active: 35392 kB
Inactive: 44180 kB
Active(anon): 26540 kB
Inactive(anon): 28244 kB
Active(file): 8852 kB
Inactive(file): 15936 kB
Unevictable: 280 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 52688 kB
Mapped: 17960 kB
Slab: 3816 kB
SReclaimable: 936 kB
SUnreclaim: 2880 kB
PageTables: 5260 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 47048 kB
Committed_AS: 1483784 kB
VmallocTotal: 876544 kB
VmallocUsed: 15456 kB
VmallocChunk: 829444 kB
#
下面先对"/proc/meminfo"文件里列出的字段进行粗略解释:
MemTotal: 所有可用RAM大小。
MemFree: LowFree与HighFree的总和,被系统留着未使用的内存。
Buffers: 用来给文件做缓冲大小。
Cached: 被高速缓冲存储器(cache memory)用的内存的大小(等于diskcache minus SwapCache)。
SwapCached:被高速缓冲存储器(cache memory)用的交换空间的大小。已经被交换出来的内存,仍然被存放在swapfile中,用来在需要的时候很快的被替换而不需要再次打开I/O端口。
Active: 在活跃使用中的缓冲或高速缓冲存储器页面文件的大小,除非非常必要,否则不会被移作他用。
Inactive: 在不经常使用中的缓冲或高速缓冲存储器页面文件的大小,可能被用于其他途径。
SwapTotal: 交换空间的总大小。
SwapFree: 未被使用交换空间的大小。
Dirty: 等待被写回到磁盘的内存大小。
Writeback: 正在被写回到磁盘的内存大小。
AnonPages:未映射页的内存大小。
Mapped: 设备和文件等映射的大小。
Slab: 内核数据结构缓存的大小,可以减少申请和释放内存带来的消耗。
SReclaimable:可收回Slab的大小。
SUnreclaim:不可收回Slab的大小(SUnreclaim+SReclaimable=Slab)。
PageTables:管理内存分页页面的索引表的大小。
NFS_Unstable:不稳定页表的大小。
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
1. CharSequence接口定义了一个只读的char序列。String 实现 CharSequence , Serializable , Comaprable<String>
2. 由 char[] value, int offset, int count 和 int hash组成。
3. 构造函数 public String(String original) 基本上来说是没用的,因为String本身是immutable的,没必要copy一下。但有一个用处:节省空间。比如说,你用subString生成的一个String,它是重用原来的char[]的,而原来的那个String你已经不想用了(这个条件很重要), 你可以用这个构造函数重建一个String来释放空间。
public String(String original) {
int size = original.count;
char[] originalValue = original.value;
char[] v;
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
int off = original.offset;
v = Arrays.copyOfRange(originalValue, off, off+size);
} else {
// The array representing the String is the same
// size as the String, so no point in making a copy.
v = originalValue;
}
this.offset = 0;
this.count = size;
this.value = v;
}
4. 提供了一组构造函数,按照给定的Charset来将一个byte 数组 decode成一个字符串。
5. 接收StringBuilder或StringBuffer的构造函数,会将StringBuilder或StringBuffer先toString() 然后将新生成的String中的value , offset 和count赋值给当前String,这时会将char array拷贝一份,所以之后StringBuilder或StringBuffer的修改不会影响到生成的String。但问题是这样不就多生成了一个String对象么?
6. length()返回的是count的值,也就是说是Code Unit的个数,而不是Code Point的个数, 对于Supplementary Character这个length()不是字符个数。如果想得到Code Point的个数可以使用codePointCount方法。
7. getBytes方法,当不传Charset时就用系统默认的Charset将字符串转成相应的编码。
8. public boolean contentEquals(StringBuffer sb) 对 sb作了同步,防止sb中途被修改:
public boolean contentEquals(StringBuffer sb) {
synchronized(sb) {
return contentEquals((CharSequence)sb);
}
}
9. public boolean contentEquals(CharSequence cs) 对StringBuilder和StringBuffer做了特殊处理,这样就避免在调用StringBuilder或StringBUffer的charAt方法时做的边界检查了:
public boolean contentEquals(CharSequence cs) {
if (count != cs.length())
return false;
// Argument is a StringBuffer, StringBuilder
if (cs instanceof AbstractStringBuilder) {
char v1[] = value;
char v2[] = ((AbstractStringBuilder)cs).getValue();
int i = offset;
int j = 0;
int n = count;
while (n-- != 0) {
if (v1[i++] != v2[j++])
return false;
}
return true;
}
// Argument is a String
if (cs.equals(this))
return true;
// Argument is a generic CharSequence
char v1[] = value;
int i = offset;
int j = 0;
int n = count;
while (n-- != 0) {
if (v1[i++] != cs.charAt(j++))
return false;
}
return true;
}
10. 当作Case Insensitve比较时代价有点高:
public boolean regionMatches(boolean ignoreCase, int toffset,
String other, int ooffset, int len) {
char ta[] = value;
int to = offset + toffset;
char pa[] = other.value;
int po = other.offset + ooffset;
// Note: toffset, ooffset, or len might be near -1>>>1.
if ((ooffset < 0) || (toffset < 0) || (toffset > (long)count - len) ||
(ooffset > (long)other.count - len)) {
return false;
}
while (len-- > 0) {
char c1 = ta[to++];
char c2 = pa[po++];
if (c1 == c2) {
continue;
}
if (ignoreCase) {
// If characters don't match but case may be ignored,
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check before
// exiting.
if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
continue;
}
}
return false;
}
return true;
}
11. hashCode的计算:
public int hashCode() {
int h = hash;
if (h == 0 && count > 0) {
int off = offset;
char val[] = value;
int len = count;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
}
12. String, StringBuilder和StringBuffer 共享了一段indexOf的逻辑:
static int indexOf(char[] source, int sourceOffset, int sourceCount,
char[] target, int targetOffset, int targetCount,
int fromIndex) {
if (fromIndex >= sourceCount) {
return (targetCount == 0 ? sourceCount : -1);
}
if (fromIndex < 0) {
fromIndex = 0;
}
if (targetCount == 0) {
return fromIndex;
}
char first = target[targetOffset];
int max = sourceOffset + (sourceCount - targetCount);
for (int i = sourceOffset + fromIndex; i <= max; i++) {
/* Look for first character. */
if (source[i] != first) {
while (++i <= max && source[i] != first);
}
/* Found first character, now look at the rest of v2 */
if (i <= max) {
int j = i + 1;
int end = j + targetCount - 1;
for (int k = targetOffset + 1; j < end && source[j] ==
target[k]; j++, k++);
if (j == end) {
/* Found whole string. */
return i - sourceOffset;
}
}
}
return -1;
}
由此可见,想让indexOf(String substr, int fromIndex) 返回String.length()的唯一方法是, fromIndex >= String.length(),并且子串为空串。
13. lastIndexOf写得有点奇怪:
static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
char[] target, int targetOffset, int targetCount,
int fromIndex) {
/*
* Check arguments; return immediately where possible. For
* consistency, don't check for null str.
*/
int rightIndex = sourceCount - targetCount;
if (fromIndex < 0) {
return -1;
}
if (fromIndex > rightIndex) {
fromIndex = rightIndex;
}
/* Empty string always matches. */
if (targetCount == 0) {
return fromIndex;
}
int strLastIndex = targetOffset + targetCount - 1;
char strLastChar = target[strLastIndex];
int min = sourceOffset + targetCount - 1;
int i = min + fromIndex;
startSearchForLastChar:
while (true) {
while (i >= min && source[i] != strLastChar) {
i--;
}
if (i < min) {
return -1;
}
int j = i - 1;
int start = j - (targetCount - 1);
int k = strLastIndex - 1;
while (j > start) {
if (source[j--] != target[k--]) {
/*
* 获取el被缩放的倍数
*/
getZoomLeve : function(el) {
// 标示缩放的css属性
var zoomPer, undefinedPer = 'none';
if(S.UA['firefox']) {
zoomPer = '-moz-transform';
}
else if(S.UA['ie']) {
if(S.UA['ie'] == 9) {
zoomPer = '-ms-transform';
} else {
zoomPer = 'zoom';
undefinedPer = 'normal';
}
}
else {
zoomPer = '-webkit-transform';
}
var ret = 1;
// 先计算元素在Iframe内部被缩放的大小
while(el.ownerDocument != document) {
ret *= getZoom(el);
var $ifrs = $('iframe'),
curWin = el.ownerWindow,
ifr;
S.each($ifrs, function(item) {
try{
if(item.contentWindow == curWin) {
ifr = item;
return false;
}
}catch(e) {
// 捕获跨域访问的错误
}
});
if(ifr) {
el = ifr;
} else {
break;
}
}
ret *= getZoom(el);
function getZoom(htmlEl) {
var ret = 1;
// 这里的add将el的缩放也计算在内
S.each($(htmlEl).parents().add($(htmlEl)),function(el) {
if($(el).css(zoomPer) && $(el).css(zoomPer)!=undefinedPer) {
if(S.UA['ie'] && S.UA['ie']<9) {
ret *= el.style.zoom;
} else {
var temp = $(el).css(zoomPer),
start = temp.indexOf('(') + 1,
end = temp.indexOf(',');
ret *= temp.substring(start, end);
}
}
});
return ret;
}
return ret;
}
代码中的S是KISSY的缩写。