I*******e 发帖数: 1879 | 1 ☆─────────────────────────────────────☆
yanb (大象 内旋内扣内韧 ) 于 (Thu Apr 9 19:49:22 2009) 提到:
假设有个Vector对象,不停地改变长短,每改变一次就作为serialized object往
socket里面发送,但得不到预期结果。
发现必须每次都new一个新对象来拷贝这个Vector对象的内容,然后发送这个新对象。
这样Vector对象改变一万次,作为程序员就得new一万个新对象来发送,还有天理么?
java这种只用reference的方式让c++程序员很难受吧?
☆─────────────────────────────────────☆
shuiguan (guanshui) 于 (Thu Apr 9 20:35:25 2009) 提到:
c++有serialization嘛?
试一下 ObjectOutputStream.reset()
☆─────────────────────────────────────☆
goodbug (好虫) 于 (Fri Ap | f**y 发帖数: 138 | 2 I believe when you write the same object to the socket with a loop,
the update on the object won't be reflected in the stream by default.
You'd better call enableReplaceObject(true) on the output stream
before sending the vectors. With every writeObject() call, the output
stream checks if the object referenced is already in the stream. If
so, it won't copy the object. Instead, it will just share the
same object you write to it at the first time.
After enableReplaceObject(true) has been called, t
【在 I*******e 的大作中提到】 : ☆─────────────────────────────────────☆ : yanb (大象 内旋内扣内韧 ) 于 (Thu Apr 9 19:49:22 2009) 提到: : 假设有个Vector对象,不停地改变长短,每改变一次就作为serialized object往 : socket里面发送,但得不到预期结果。 : 发现必须每次都new一个新对象来拷贝这个Vector对象的内容,然后发送这个新对象。 : 这样Vector对象改变一万次,作为程序员就得new一万个新对象来发送,还有天理么? : java这种只用reference的方式让c++程序员很难受吧? : ☆─────────────────────────────────────☆ : shuiguan (guanshui) 于 (Thu Apr 9 20:35:25 2009) 提到: : c++有serialization嘛?
|
|