Hello,
Thank you so much for cffi, it is a really amazing module and I'm having a lot of fun with it.
I have a question about accessing a mmap objects buffer interface. I don't know much about this little used corner of the language, but as I gather mmap objects support the buffer interface that allows the memory "backing" the mmap to be accessed directly without copying. There is a function that the zeromq library exposes, called zmq_zmsg_init_data that accepts a pointer to an existing buffer that is to be used as the source of a message object to do "zero-copy" (really one-less-copy) messaging. Here's my code:
mapped = mmap.mmap(f.fileno(), 0)
...
for i in range(numpoints):
msg = ffi.new('zmq_msg_t*')
pos = psize*i
zmq.msg_init_data(
msg,
buffer(mapped, pos, psize),
psize,
free,
ffi.NULL)
zmq.sendmsg(sock, msg, 0)
The mapped file a sequence of 'numpoints' data chunks 'psize' in length. but unfortunately that doesn't work, cffi throws a typerror that it needs void* instead of a buffer. If I do buffer(mapped)[pos:pos+psize] it works, but I suspect that's causing a copy operation, although I'm not certain. It seems like the right thing to do would be to accept a buffer object in place of a cdata pointer, but again I have really limited knowledge of what the right approach here is. I know what I want from a high level, the already mapped memory being used as the buffer for the message, with no copying in or out, but I'm not sure how to get there.
Any tips?
-Michel