0

我有一个从 Internet 下载的 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);
}

}

我的日志猫

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 中的分配跟踪器

我在 DDMS 中的分配跟踪器

4

0 回答 0