Resource Manager: Avoid extra copy in io_write

Hi All

I am using a resource manager to feed packets to my network driver. However, in transmit side I am having to perform a
full extra copy of the frame due to problem mentioned below. Please help me in understanding this situation better.

QNX documentation mentions following about handling io_write message while writing a resource manager:

buf = (char *) malloc(msg->i.nbytes + 1);
if (buf == NULL)

 *  Reread the data from the sender's message buffer.
 *  We're not assuming that all of the data fit into the
 *  resource manager library's receive buffer.

resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(msg->i));
buf [msg->i.nbytes] = '\0'; /* just in case the text is not NULL terminated */
printf ("Received %d bytes = '%s'\n", msg -> i.nbytes, buf);

I want to understant the importance of resmgr_msgread API here and the comment above it.

I need to write the packet to the SRAM of a device which is memory mapped into my process (resource manager). However,
If I pass the pointer to mapped memory directly into resmgr_msgread, it fails with errno ESRVRFAULT.

This now requires me to pass a local buffer to get the data from client and then copy it again into memory mapped space
in device SRAM causing performance issues under load.

Please help me optimize performance of my system by removing this additional copy.


The extra copy is probably not the issue here, it`s the malloc. If possible try to optimize that by reusing the same memory space and only growing it if needed.

That being said if you get an ESRVFAULT when callsing resmgr_msgread its because your pointer is not pointing to valide memory, or that the size specified is too small for the specified memory block. Its basically a SIGSEGV.

It sounds like (maybe, the original question is very unclear) you want to know why you can’t move data between two processes using a pointer, but instead have to copy the data itself?

If so, you should understand that in most circumstances, a pointer in one process is meaningless in another. There are two exceptions I can think of. 1) You are passing data between two threads in the same process. 2) The data is in shared memory that you have requested be mapped to the same location.

If you really need this type of performance, I recommend using offsets into a shared memory segment.
However, unless you are using a Gigabit network, you might want to do a little order of magnitude calculation as to whether eliminating a copy will help all that much.