Hello there,
As titled, I have no ideas about the difference between resmgr_msgread() and resmgr_msgget() even if after I have checked the official document.
In addition, how does resmgr_msgget() execute more efficiently than resmgr_msgread()?
Here’s the description of resmgr_msgread() in the official document:
The resmgr_msgread() function is a convenience function that you can use in a resource manager
instead of MsgRead(). However, for efficiency, you should use resmgr_msgget() instead.
You’ll use resmgr_msgread() when you handle combine messages, where the offset of the rest of the
message that’s to be read is additionally offset by previous combine message elements.
The description of resmgr_msgget() in the official document:
The resmgr_msgget() function is a convenience function that you can use in a resource manager instead
of resmgr_msgread() or MsgRead().
Based on the requested data offset, this function first copies data from the current local message
buffer (if applicable) and then gets the rest of the data (if applicable) from the client by calling
MsgRead() .
Because combine message offsets are automatically handled, the caller does not add the offset that
ctp references to the passed in offset. The passed in offset is just the offset from the start of the
current message being processed.
For combine messages (those with the _IO_COMBINE_FLAG set), the amount of data returned to the
caller is limited to the size found in the size parameter referenced by ctp . This limit ensures that the
caller does not get data from a subsequent message by mistake.
Thanks in advance.
I haven’t used either of these functions, but I have an idea of what is going on. Before I get into the meat of this a couple questions.
- Do you handle large messages in your resource manager. In principle, unless you are in a highly constrained memory environment or you have seriously large messages that either you can’t allocate a buffer for in the RM, or you can’t handle in the client, there is no need for either of these functions.
- Do you handle combine messages? These is quite rare. The only usage I know of is if you are dealing with a file system in which you want an atomic seek and read. This is not required unless you are supporting multiple opens to the file. If not, you can forget about msgget().
So both of these routines are used in a situation where the message you are going to get is large and you want to just read the header in your msg_receive() call and then allocate room to pull the rest of the message in. If you know the maximum size your messages are going to be and you can allocate a buffer that size, it is much simpler. On the other hand, if you are in a cpu constrained environment, you can reduce the copying of the message information by 1 using these routines at the expense of the overhead of another kernel call. Unless the messages are large, this makes no sense.
As best I can tell, the reason for using msgget() only applies if you are reading combine messages. Having never dealt with them I don’t know the ‘offset’ details that msgget() takes care of for you. In many years of writing resource managers, I’ve never needed to consider this and would avoid it if possible.
Oh, and if you just asking out of curiousity, I would suggest you make believe that these calls don’t exist until you come across a situation where they are needed, which may well be never.