Forums Register Login

what is handle and first reference in serialization

+Pie Number of slices to send: Send
I am reading on serialization topic from the the following url:
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serial-arch.html#5800

In 1.2 Writing to an Object Stream section,I could not understand the following statement.Can you explain this,especially the first reference and handle.

statement
---------
Within a stream, the first reference to any object results in the object being serialized or externalized and the assignment of a handle for that object. Subsequent references to that object are encoded as the handle.
+Pie Number of slices to send: Send
Say you had two objects a and b. a has a variable that refers to b and b has a variable that refers to a. When you serialize a the object stream drills down and serializes b. While doing that it finds a reference to a. If it tried to serialize a from scratch again it would be in an endless loop. Instead it recognizes that a is already in stream (maybe not complete yet?) so it can serialize b with a "handle" to a. When it de-serializes it can use the handles to reconstruct the reference variables.

The same thing can happen in more complex object graphs even without cycles, say maybe a, b and c all refer to d.

That seemed to take way too many words to describe. Did it make any sense?
+Pie Number of slices to send: Send
Thank you for your clear explanation.
And inside of my fortune cookie was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 804 times.
Similar Threads
Is Serialization like taking a picture of memory cells content?
Why Serialization ignores static fields?
anonymous inner class with rmi
java.io.Serializable
Why Serialization?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:37:08.