简体   繁体   中英

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 container, 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

您可以使用地图通过messageID轻松获取结构: http : messageID

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 .

除了std::mapboost::unordered_map ,如果您打算遍历给定senderID的消息,则可以使用boost::multi_index_container

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM