Hello,
Serialization in
Java is an old topic, but here I'm asking a very lightweight serialization, hopefully as lightweight as memory copy. In C/C++, if I want to convert a double or integer into a byte array, I can simply convert the type and do memory copy (or even memory copy can be saved). I wonder if Java provides some method to do the similar thing.
Right now the best I can get is use DataOutputStream.writeDouble() or .writeInt() to convert doubles or integers to byte array. To convert a byte array to corresponding typed data, I do something as follows:
ra = Double.longBitsToDouble(Long.reverseBytes(in.readLong()));
dec = Double.longBitsToDouble(Long.reverseBytes(in.readLong()));
objID = Long.reverseBytes(in.readLong());
x = Double.longBitsToDouble(Long.reverseBytes(in.readLong()));
y = Double.longBitsToDouble(Long.reverseBytes(in.readLong()));
z = Double.longBitsToDouble(Long.reverseBytes(in.readLong()));
These operations might be nothing for powerful servers. But for Atom processors, it's still quite heavy when working on several hundred GB data.
So any ideas how to convert between typed data and byte arrays more lightweightly?
Thanks,
Da