我有一个程序,其中通过套接字使用 ObjectStream。我发送的类的代码如下所示。
class Snake{
Point[] p = new Point[50];
Direction move;
public int length;
int score;
String player;
Color snakecolor;
boolean gameover;
//Other Functions go here//
}
该类通过套接字重复发送。然而它显示出一点滞后。如果不发送 Color 对象而是发送 RGB 代码(整数值),会有那么大的区别吗?我怎样才能让我的程序没有延迟?
最佳答案
来自documentation ,Color
的以下字段被序列化:
int value
float[] frgbvalue
float[] fvalue
float falpha
ColorSpace cs
色彩空间
has the following serialized fields :
int type
int numComponents
frgbValue
和 fvalue
包含 3 个元素,因此总大小为 40 字节。仅发送 RGB 就需要 12 个字节。我不认为这能解决你的滞后问题。
关于java - java.awt.Color 对象的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15932257/