我有一个从互联网上下载的java课程。
代码原始写入在PC上运行。
当我在Android手机上运行代码时,内存的分配限制会导致 系统需要等待“垃圾收集”。
我认为如果有任何方法可以重写原始代码并让
每次只编程新对象而不是新对象。
package com.example.ardrone_hu;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.nio.ByteBuffer;
public class uint {
public String toString() {
return Integer.toString(base2, 2);
}
public uint(int base) {
this.base2 = base;
}
public uint(uint that) {
this.base2 = that.base2;
}
public uint(byte[] bp, int start) {
try {
byte[] b = new byte[4];
b[0] = bp[start + 3];
b[1] = bp[start + 2];
b[2] = bp[start + 1];
b[3] = bp[start + 0];
ByteArrayInputStream bas = new ByteArrayInputStream(b);
DataInputStream din = new DataInputStream(bas);
this.base2 = din.readInt();
} catch (Exception e) {
throw new RuntimeException("error creating uint", e);
}
}
public uint(ByteBuffer bp, int start) {
try {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.put(bp.array()[start + 3]);
bb.put(bp.array()[start + 2]);
bb.put(bp.array()[start + 1]);
bb.put(bp.array()[start + 0]);
bb.flip();
this.base2 = bb.getInt();
} catch (Exception e) {
throw new RuntimeException("error creating uint", e);
}
}
private int base2;
public short times(short i) {
return (short) (intValue() * i);
}
public uint shiftRight(int i) {
// System.out.println("shiftRight[0] " + base2 + " " + i);
// String str = Integer.toBinaryString(base);
int base = base2;
// System.out.println("shiftRight[n][1] " + uint.toBinaryString(base));
base = base >>> i;
// System.out.println("shiftRight[n][2] " + uint.toBinaryString(base));
return new uint(base);
}
public uint shiftLeft(int i) {
int base = base2;
base <<= i;
return new uint(base);
// return Integer.parseInt(base, 2);
}
public int flipBits() {
int base = ~base2;
return base;
}
public int intValue() {
return base2;
}
public uint and(int andval) {
int retval = base2 & andval;
return new uint(retval);
}
public void shiftLeftEquals(int i) {
int base = base2;
base <<= i;
base2 = base;
}
public void shiftRightEquals(int i) {
int base = base2;
base >>>= i;
base2 = base;
}
public uint or(uint orval) {
int retval = base2 | orval.base2;
return new uint(retval);
}
}
我的LogCat
05-23 22:59:38.828: D/dalvikvm(31423): WAIT_FOR_CONCURRENT_GC blocked 91ms
05-23 22:59:38.903: D/dalvikvm(31423): GC_CONCURRENT freed 675K, 17% free 11374K/13575K, paused 1ms+7ms, total 37ms
05-23 22:59:38.978: D/dalvikvm(31423): WAIT_FOR_CONCURRENT_GC blocked 102ms
05-23 22:59:39.103: D/dalvikvm(31423): GC_CONCURRENT freed 675K, 17% free 11374K/13575K, paused 2ms+11ms, total 63ms
05-23 22:59:39.168: D/dalvikvm(31423): WAIT_FOR_CONCURRENT_GC blocked 113ms
05-23 22:59:39.263: D/dalvikvm(31423): GC_CONCURRENT freed 675K, 17% free 11374K/13575K, paused 1ms+9ms, total 48ms
05-23 22:59:39.328: D/dalvikvm(31423): WAIT_FOR_CONCURRENT_GC blocked 102ms
05-23 22:59:39.413: D/dalvikvm(31423): GC_CONCURRENT freed 675K, 17% free 11375K/13575K, paused 1ms+7ms, total 42ms
05-23 22:59:39.488: D/dalvikvm(31423): WAIT_FOR_CONCURRENT_GC blocked 101ms
我在DDMS中的分配跟踪器