I can send large messages, which are only limited by malloc(). However, how would I give the user threads access to the data if the size of the message can vary that much?
- I allocate virtual pages and fill them with a copy of the message. Pros: only the requested message is accessible; Cons: this is space-wasteful if small messages are passed (it takes a whole page anyways), unless the app copies the data to its own heap and requests to dealloc the page struct;
- Firstly make a call to the kernel to request the message's size, allocate a buffer and request the message to be copied into the buffer. Pros: doesn't waste memory because of page-granulity; works quite well; Cons: It would require the infastructure to get the message's size, and some time later, get the SAME message to be copied. Perhaps this is doable;
- Share the kernel structures which contain the message for reading access for the user app. Pros: least memory overhead, least memory movin'/copyin'. This would allow the app to access the data without allocating new buffers. Cons: apart from the message, other data which are near the message, like other messages or book keeping structs are availlable for the thread for reading. Also, there would need to be a call to dispose the message later.
- The thread may as well read the message as if it was a socket, so it would read it in small 128-byte (or any other granulity) bits until it was read completely read. Pros: well not much here; Cons: This would need a complex infrastructure for the sockets, if I wanted to do this properly. Also, the user app would need to read from the socket before it could do anything useful with the message. The first few bytes would contain a header though, so after the first read the message's size would be known.
Cheers,
Adrian.