[zeromq-dev] zmq_recvmsg jni

Artem Vysochyn artem.vysochyn at gmail.com
Wed Oct 2 17:30:21 CEST 2013


hi Trevor,

Can you past example(s) of how you use DirectByteBuffer in jzmq? pls.

2013/10/2 Trevor Bernard <trevor.bernard at gmail.com>:
> I do that very thing with a different method signature.
>
> https://github.com/trevorbernard/zmq-jni/blob/master/src/main/c%2B%2B/zmq.cpp#L169
>
> 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
> pressure.
>
> 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
>>
> _______________________________________________
> 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