Thanks, I hadn't actually changed any of my code yet, I was just typing that into email after a quick Google search yielded:
http://www.exampledepot.com/egs/java.nio/Buf2Array.html

I decided to take Bryan up on the offer to submit a patch for 0.4.1 instead.
I did some quick performance testing of the 0.4 implementation compared to 0.2 by serializing a struct with two 100-byte binary fields a million times, and then deserializing. The 0.4 implementation was about 10% slower due to all of the extra wrapping and unwrapping, but total memory usage was about 10% less. I.e. the performance is a wash for anything we're doing, and the conversion's a hassle (breaking all of our usage of Thrift structs as POJO data structures), so I'll add a compiler option.

Thanks


On 8/26/10 3:03 PM, Mathias Herberts wrote:
The changes you intend to do to your code are not correct.
ByteBuffer.capacity() does not return the actual size of the data
stored in a ByteBuffer.

The size is actually ByteBuffer.limit() - ByteBuffer.arrayOffset().

And by creating a new byte[] you copy the data and do not hold a
reference to it. Which means that if you modify the returned byte[] it
won't be reflected in the Thrift struct.

I can only agree that this one change is a pain in the b... to deal with.


Reply via email to