Updated: 4/6/2003; 10:22:51 AM.
 
Ockham's Flashlight
Stuart Halloway on software development, technology, and the future.
        

Friday, April 04, 2003

Cameron claims that an Integer takes 81 bytes in the serialized form. A quick experiment reveals that this is *not* true in general--the "limit" overhead for serializing an Integer is 10 bytes. Since Cameron probably arrived at the figure 81 somehow, what is going on here?

The issue is data versus metadata. Java serialization carries not only instance data, but also metadata about the classes being serialized. This enables interesting behavior such as recovery by the receiver even if classes have changed since the data was serialized. It also makes the serialized form fatter, but this bloat is per class, not per instance. So the first time you serialize an Integer takes well more than ten bytes. After that, it's ten. Of course, ten bytes isn't so great either, since the Integer itself is only four bytes long. For classes in general, there are good reasons for this overhead, but the reasons don't apply very well to Integer. So just say no. You shouldn't be serializing Integer anyway--use primitive types on the wire.

My book ( which is free in PDF form) talks about these issues in detail.
11:05:13 PM    comment []


© Copyright 2003 Stuart Halloway.
 
April 2003
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
Mar   May

About me

Teaching
The book
Speaking
Articles
Bio
CV
Java/COM/Win32 interop
Jawin
Contact


Subscribe to "Ockham's Flashlight" in Radio UserLand.

Click to see the XML version of this web page.