开发者

c++ struct and container

I am writing a small software which deals with inter-process multicast. For each message, on each process, I have a couple of variables assigned to the message itself:

messageID
senderID
ack1
ack2
ack3
...

I would like to put these elements (which are many) in a cont开发者_运维知识库ainer, so that it is later easy to perform operations such as changing the value of ack1 for a given messageID (I should keep trace of which processes in my group notified me that they got the message).

Which is the best container to use in this case?

Thanks


You might want to use std::map or boost::unordered_map (soon to be standard) as you can access it by message id.
Next time you'd want to answer such a question alone, take a look at this diagram.


You can use a map to easily fetch a structure by messageID: http://www.cplusplus.com/reference/stl/map/


In addition to std::map and boost::unordered_map, if you plan to iterate over the messages from a given senderID you can use boost::multi_index_container.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜