This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MessageQ messages

As I have been reading through the MessageQ Doxygen and CDoc docs, I am left with a few questions pertaining to message sizes passed through MessageQs. The CDoc claims that you can define any custom message so long as the structure contains the MessageQ_header struct as the first element. So that requires defining a new type, and casting calls to MessageQ_alloc/_free/_put/_get as appropriate. Now do the alloc and free calls set the MessageQ_header.size field accordingly? Or do I have to do that manually after the alloc, before I _put the message?

Bios  6.30.02.42

IPC 1.21.02.23

  • Hi,

    Inside the MessageQ_alloc(), the size field is set (along with other fields). You should not act on any of the fields of the MessageQ_msgHeader directly since it may change. There are wrapper APIs to get to the information or to set some of the fields (e.g. MessageQ_setReplyQueue).

    The size saved in the header is the size requested in the MessageQ_alloc. The actual size might be bigger depending on the heap implementation (e.g. to honor cache lines, etc.). Note, make sure the size you request includes the size of the MessageQ_MsgHeader. An easy way to do this is simply specify the size of the structure which includes the MessageQ_Msgeader

    You do not need to specify the size in the MessageQ_free or MessageQ_put since it is embedded in the header. Since MessageQ is zero-copy based (passing of pointers...not copying the message), MessageQ_get does not take a size. The application can determine the size of the received message via the MessageQ_getMsgSize() API.

    A useful field in the MessageQ_Header is the msgId. This is completely controlled by the application. It is intended to be used to help the application determine what type of messsage it is. For example, after you allocate a msg, you can call MessageQ_setMsgId(msg, MYSTRUCT1), where MYSTRUCT1 is some constant defined by you. When you receive the msg, you can look at the msgId (via MessageQ_getMsgId()). Based on the value, you know what type of message it is and how to cast it. For example

    if (MessageQ_getMsgId(msg) == MYSTRUCT1 ) {
        ...

    This is an easy way to allow a single MessageQ to be used to receive different types of messages.

    Fyi: All the source code is provided with Ipc.

    Hope that helps,
    Todd