What is the fastest way to fill up a pre-allocated ByteBuffer
in Java?
I first set the size of the byte buffer with allocateDirect()
, this only needs to be done once. After, I need to fill it up continuously (recycling it) as fast as possible with new data which arrives as a byte[]
array, around every 5ms, and without eating memory as I have already pre-allocated the byte buffer.
At the moment, I use the put()
instruction, which in my system takes around 100ms to complete.
Is there another way to fill up the byte buffer? Does thewrap()
function run faster without re-allocating the array?