News for hackers. Stuff that matters.
Re:Native C/C++ Like Performance For Java Object Serialisation by dxbydt on Thursday July 05, 2012 @04:18PM (#4204766)
You use unsafe.putLong(), unsafe.putByte(), unsafe.putInt() to directly store a value into a given memory address. You then use unsafe.getLong() etc to directly read those values back from memory. This get you native C-like performance of only 78 ns, roughly 130 times faster than Java's 11,000 ns, very impressive! But when it comes to allocating memory, you use "new byte[1024]", a straight Java call. Using malloc ie. unsafe.allocateMemory(...), to get a larger byteblock and writing into it would probably speed up the routine even more. You also have the free ie. unsafe.freeMemory for the cleanup. (http://www.docjar.com/docs/api/sun/misc/Unsafe.html )
Re:Native C/C++ Like Performance For Java Object Serialisation by mjpt777 on Thursday July 05, 2012 @04:26PM (#4204801)
The byte[] buffer is deliberate because that is what will typically be passed to the network or IO device, so easier integration.

If you check the code you will see the buffer is only allocated once so the cost is not an issue.