Re: object serialisation
On 11/18/2010 7:07 PM, feng wrote:
Hi,
I can't understand the object serialisation concepts. The definition
is attached below. objects are already sequence of bits stored in a
file or memory buffer. [...]
Stop right there.
String str = "feng";
String[] arr = { str, str, "Hello, world!", str };
Now, consider the "sequence of bits" that makes up `arr'. Observe
that the letter 'f' appears three times in the array's contents,
yet there is only one 'f' in the program. How can one single 'f'
appear three times in a "sequence of bits" without triplication?
"Ah," I hear you say, "The elements of `arr' are not Strings,
but references to Strings. There are three references to the lone
String containing an 'f', and you, Sosman, are fffull of it!"
... but keep going: Suppose you gather up the "sequence of bits"
that represent those references, and send them across a network to a
remote JVM. Question: What can the remote JVM *do* with them? Does
it even know about the `f'? No, it only received the references as
a "sequence of bits," not the Strings those references referred to.
You sent an array of references to Strings, but you didn't send the
Strings themselves, and the remote JVM is helpless.
In serialization, both the references *and* the things they refer
to are packaged up for transmission. When you consider that a single
object may hold references to many other objects, which in turn may
hold references to still more objects, I think you'll see that the
problem is not merely transmitting a block of memory, but transmitting
an encoding of an arbitrarily complicated graph. The graph may even
contain cycles: consider a tree-like structure where each node has
references to its children *and* each child refers to its parent, for
example.
file or memory buffer. so why all references define serialisation as a
mean to convert an object to a sequence of bits? I thought casting a
block of bits is more enough to resurrect the object or any other data
structure. any clarification please?
By now, I hope you understand that "sequence of bits" is inadequate
as a model for a Java object.
--
Eric Sosman
esosman@ieee-dot-org.invalid