I'm not opposed to using a heap allocated bytebuffer but we gain no benefit compared to doing something like this:
byte[] buf = socket.recv(1) ByteBuffer bb = ByteBuffer/wrap(buf); The problem with heap allocated ByteBuffer and JNI interop if I'm not mistaken, there is no way to convert a java byte[] into a malloc'ed piece of memory in without copying. You'll always be at least one copy at the JNI level. In the case of using ByteBuffer.allocateDirect(...); There will never by any coping at the JNI level. GetDirectBufferAddress returns the pointer to the off heap memory location that you can pass into zmq_msg_init_data for true zero copy or into zmq_send. On Mon, May 13, 2013 at 2:35 PM, Parag Patel <parag.pa...@fusionts.com>wrote: > Why not just call ByteBuffer.wrap? The array that is returned today is > already copied. When you wrap, you’re essentially creating a ByteBuffer > that references the byte[] passed back by zeromq. When you allocate > direct, you’re unnecessarily copying this byte[] again.**** > > ** ** > > Parag**** > > ** ** > > *From:* zeromq-dev-boun...@lists.zeromq.org [mailto: > zeromq-dev-boun...@lists.zeromq.org] *On Behalf Of *Trevor Bernard > *Sent:* Monday, May 13, 2013 12:59 PM > *To:* ZeroMQ development list > *Subject:* [zeromq-dev] ByteBuffer API for JZMQ**** > > ** ** > > In the next couple of days I will be writing a ByteByffer API for JZMQ I > would like to hear the communities thoughts.**** > > ** ** > > I was thinking of something along the lines of:**** > > ** ** > > int sendByteBuffer(ByteBuffer bb, int flags);**** > > int recvByteBuffer(ByteBuffer bb, int flags);**** > > int recvByteBuffer(int flags);**** > > ** ** > > Implementation seems straightforward enough. Though it really only makes > sense to use a Direct ByteBuffer since it's allocated off the heap and can > be passed to libzmq without a copy. Otherwise you'd have to copy the > underlying byte[].**** > > ** ** > > So does it make sense to only support a direct bytebuffer?**** > > ** ** > > Thoughts?**** > > ** ** > > -Trev**** > > _______________________________________________ > zeromq-dev mailing list > zeromq-dev@lists.zeromq.org > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > >
_______________________________________________ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev