hi Trevor,
Thanks for posting this. Very nice.
Still curious. Does it mean that using DirectByteBuffer only makes
sense if one uses ZMQ+Disruptor?
Second question:
...
ByteBuffer bb = ByteBuffer.allocateDirect(4096);
socket.recvByteBuffer(bb, 0);
...
I also had been thinking about such
Ok, I see this:
/**
* Receive a message in to a specified buffer.
*
* @param buffer
*byte[] to copy zmq message payload in to.
* @param offset
*offset in buffer to write data
* @param len
*
Still curious. Does it mean that using DirectByteBuffer only makes
sense if one uses ZMQ+Disruptor?
Not at all. That's just one example of how I do it.
-- what we win here
There is no way (that I know of) to pass a Java byte array to the
underlying c/c++ function without a copy. What the
There is no way (that I know of) to pass a Java byte array to the underlying
c/c++ function without a copy. What the DirectByteBuffer allows you to do is
get the pointer to the memory region it references and you can pass this
along to zmq_recv eliminating the need to do a copy between
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
I'm using a slightly different approach, by using 2 jni calls only (one for
allocation and a general purpose call) and 2 memory arenas (one input, one
output) as registers
all the logic is implemented strictly in c++ and the data passed via the
arena is strictly java primitives (I have a generic
hi Trevor,
Can you past example(s) of how you use DirectByteBuffer in jzmq? pls.
2013/10/2 Trevor Bernard trevor.bern...@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
It's fairly straightforward.
ByteBuffer bb = ByteBuffer.allocateDirect(4096);
serialize(bb, someObj);
bb.flip();
socket.sendByteBuffer(bb, 0);
...
ByteBuffer bb = ByteBuffer.allocateDirect(4096);
socket.recvByteBuffer(bb, 0);
bb.flip();
Object deserialized = deserialize(bb);
In my use case, I
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
: Saturday, September 28, 2013 6:49 PM
To: ZeroMQ development list
Subject: [zeromq-dev] zmq_recvmsg jni
Hi guys,
I messing around with JNI and libzmq and I was wondering if there was a way
to avoid the memcpy?
JNIEXPORT
jobject JNICALL
Java_org_zeromq_jni_ZMQ_zmq_1recv__JI (JNIEnv *env
On Mon, Sep 30, 2013 at 1:05 PM, gonzalo diethelm gdieth...@dcv.cl wrote:
zmq_msg_t msg;
zmq_msg_init (msg);
zmq_recvmsg ((void *) socket, msg, flags);
int size = zmq_msg_size (msg);
void *data = malloc(size);
The zmq_recvmsg allocates the data once, and then there's a
Hi guys,
I messing around with JNI and libzmq and I was wondering if there was
a way to avoid the memcpy?
JNIEXPORT
jobject JNICALL
Java_org_zeromq_jni_ZMQ_zmq_1recv__JI (JNIEnv *env, jclass c, jlong
socket, jint flags)
{
zmq_msg_t msg;
zmq_msg_init (msg);
zmq_recvmsg ((void *)
12 matches
Mail list logo