[zeromq-dev] zmq_recvmsg jni

Trevor Bernard trevor.bernard at gmail.com
Wed Oct 2 13:23:28 CEST 2013

I do that very thing with a different method signature.


I've had some success with preallocating a bunch of DirectByteBuffers
off heap. It definitely helps with performance and GC. If I use
byte[], it generates far too much garbage and generates too much GC

On Tue, Oct 1, 2013 at 9:33 PM, Radu Braniste <rbraniste at gmail.com> wrote:
> Personally I'm using the direct buffer as a  memory arena (I preallocate a
> pool)  and I avoid one allocation like:
>>     zmq_msg_t msg;
>>     zmq_msg_init (&msg);
>>     zmq_recvmsg ((void *) socket, &msg, flags);
>>     int size = zmq_msg_size (&msg);
> //might check for out of bounds and return false
>  memcpy(GetDirectBufferAccess(arena+used), zmq_msg_data (&msg), size);
> used += size;
>>     zmq_msg_close(&msg);
>>     return used;
> the best would be of course to use this technique with a possible
> "zmq_msg_init_data" as Peter suggested and completely avoid he extra memcpy
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list