我正在制作一个游戏消息系统并使用 boost::serialize 将消息数据转换为流并发送它。这对于立即传输消息来说效果很好,因为我可以发送对流的引用。
不过,在某些情况下我也想对消息进行排队。我不确定存储数据的最佳方式是什么。
我尝试了 std::queue
但错误很多。
std::bitset 看起来很有希望,但我不确定。
或者这完全是疯了?
I'm making a game message system and using boost::serialize to convert message data into streams and sending it. This works fine for transmitting messages instantly as I can send off the reference to the stream.
However I would like to queue up messages as well in some circumstances. I am not sure what the best way to store the data would be.
I tried std::queue<std::stringstream>
but that just errors lots.
std::bitset looks semi promising, but I'm not sure.
Or is this completely bonkers?
发布评论
评论(1)
尝试
std::queue; >
。您之前尝试过的字符串流不可复制,因此只需复制字节即可。您还可以使用字符串作为队列中的值类型,因为这可能是您将从字符串流中获取的内容。Try
std::queue<std::vector<char> >
. The stringstream you tried before isn't copyable, so just copy the bytes. You could also use string as the value type in the queue, since that's probably what you'll be getting out of the stringstream.