0

私はこのクラスを持っています.RMIとkryonetとkryoを介してこのクラスを送信しています.rmiの場合、リモートメソッド呼び出しの戻り値として、およびkryonetを使用してサーバーからクライアントにエコーするkryonetの場合の両方で、10個のオブジェクトの配列を取得しています.そしてkryo、私は合計55 * 10のオブジェクトを1つ持っていますが、RMIは1196バイトです。

これらの結果は妥当ですか?

*なぜこれらの結果がそのようなものになるのですか?

なぜそんなに違いがあるのですか?

舞台裏でどのオーバーヘッドやその他の要因が関与しているか、

これは RMI でこれだけの合計を作っており、違いが大きすぎて、私を指摘しています。

単一のオブジェクトで合計 55 バイトで問題ありませんか?*.

これらの結果を提示しなければならないので、確認と専門家の目だけが必要です。

本当に感謝します。

これは私が両方で使用しているクラスです:

public class TBall {

private float x, y; // Ball's center (x, y)
private float speedX, speedY; // Ball's speed per step in x and y
private float radius; // Ball's radius
private Color color; // Ball's color

public boolean collisionDetected = false;
public static boolean run = false;

private String name;

private float nextX, nextY;
private float nextSpeedX, nextSpeedY;

public TBall() {
    super();
}

public TBall(String name1, float x, float y, float radius, float speed,
        float angleInDegree, Color color) {
    this.x = x;
    this.y = y;
    // Convert velocity from polar to rectangular x and y.
    this.speedX = speed * (float) Math.cos(Math.toRadians(angleInDegree));
    this.speedY = speed * (float) Math.sin(Math.toRadians(angleInDegree));
    this.radius = radius;
    this.color = color;
    this.name = name1;
}

public String getName() {
    return this.name;
}

public float getSpeed() {
    return (float) Math.sqrt(speedX * speedX + speedY * speedY);
}

public float getMoveAngle() {
    return (float) Math.toDegrees(Math.atan2(speedY, speedX));
}

public float getRadius() {
    return radius;
}

public Color getColor() {
    return this.color;
}

public void setColor(Color col) {
    this.color = col;
}

public float getX() {
    return x;
}

public float getY() {
    return y;
}

public void setX(float f) {
    x = (int) f;
}

public void setY(float f) {
    y = (int) f;
}

public void move() {
    if (collisionDetected) {
        // Collision detected, use the values computed.
        x = nextX;
        y = nextY;
        speedX = nextSpeedX;
        speedY = nextSpeedY;
    } else {
        // No collision, move one step and no change in speed.
        x += speedX;
        y += speedY;
    }
    collisionDetected = false; // Clear the flag for the next step

    System.out.println("In serializedBall in move.");
}

public void collideWith() {

    float minX = 0 + radius;
    float minY = 0 + radius;
    float maxX = 0 + 640 - 1 - radius;
    float maxY = 0 + 480 - 1 - radius;

    double gravAmount = 0.9811111f;
    double gravDir = (90 / 57.2960285258);

    // Try moving one full step
    nextX = x + speedX;
    nextY = y + speedY;
    System.out.println("In serializedBall in collision.");

    // If collision detected. Reflect on the x or/and y axis
    // and place the ball at the point of impact.
    if (speedX != 0) {
        if (nextX > maxX) { // Check maximum-X bound
            collisionDetected = true;
            nextSpeedX = -speedX; // Reflect
            nextSpeedY = speedY; // Same
            nextX = maxX;
            nextY = (maxX - x) * speedY / speedX + y; // speedX non-zero
        } else if (nextX < minX) { // Check minimum-X bound
            collisionDetected = true;
            nextSpeedX = -speedX; // Reflect
            nextSpeedY = speedY; // Same
            nextX = minX;
            nextY = (minX - x) * speedY / speedX + y; // speedX non-zero
        }
    }
    // In case the ball runs over both the borders.
    if (speedY != 0) {
        if (nextY > maxY) { // Check maximum-Y bound
            collisionDetected = true;
            nextSpeedX = speedX; // Same
            nextSpeedY = -speedY; // Reflect
            nextY = maxY;
            nextX = (maxY - y) * speedX / speedY + x; // speedY non-zero
        } else if (nextY < minY) { // Check minimum-Y bound
            collisionDetected = true;
            nextSpeedX = speedX; // Same
            nextSpeedY = -speedY; // Reflect
            nextY = minY;
            nextX = (minY - y) * speedX / speedY + x; // speedY non-zero
        }
    }

    System.out.println("In serializedBall collision.");
    // speedX += Math.cos(gravDir) * gravAmount;
    // speedY += Math.sin(gravDir) * gravAmount;

    System.out.println("In serializedBall in collision.");
}

}

ありがとう。

4

1 に答える 1

0

どこから「55」を入手しましたか?あなたが持っている:

9フロート、= 9x4バイト、合計36バイト1ブール、バイトとしてシリアル化、合計1バイト1文字列、任意の長さ1色、次のものが含まれます:1 int、4バイトとしてシリアル化1 float、4バイトとしてシリアル化それぞれ長さ3の2つのfloat[]、24バイトとしてシリアル化1カラースペース。これには次のものが含まれます。2int、8バイトとしてシリアル化

この合計は、少なくとも77バイトに、文字列を送信するために必要なものを加えたものです。

シリアル化では、クラス情報、バージョン情報、およびタグがすべてのアイテムの前に送信されます。RMIはメソッド情報も送信します。これらすべてが違いを簡単に説明できます。他のパッケージが何をするのかわかりません。

于 2011-06-27T00:25:04.400 に答える