Java – do you want to keep interconnected strings when serializing?

If I have a large object graph with many duplicate strings, is it good to actually () the strings before serializing them? Will this reduce the amount of data transferred? Will strings share pointers at the receiver?

My guess is that the strings will be removed before sending, so as to reduce the size of the data, and they will all be represented by the same object on the receiving end, but they will not actually be implemented on the receiving end (this means that a new string instance will be created on each serialized 'transaction')

Solution

Objectoutputstream tracks the object graph (until reset), and an object is written only once, even if it arrives through multiple references Reducing objects through practice will certainly reduce the number of bytes

At the receiving end, the same object graph is recreated, so a string instance at the sending end becomes a string instance at the receiving end

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>