哪个STL C ++容器用于固定大小的列表? [英] Which STL C++ container to use for a fixed size list?

查看:101
本文介绍了哪个STL C ++容器用于固定大小的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个消费应用程序,需要在列表中存储最多100个对象,以提供给回调进行处理,因为如果消费者不赶上,保存旧数据将是多余的。当新数据到达时,它可以简单地覆盖最旧的元素。

I am having a consuming application which needs to store a maximum of 100 objects in a list to feed to a callback for processing, since it will be redundant to keep old data if the consumer does not catch up. As new data is arrived, it can simply overwrite the oldest element.

我在想使用循环缓冲区容器,并猜测它会deque,但发现它不使用循环列表,以及没有设置固定最大大小的选项。

I was thinking of using circular buffer container and guessed that it would be deque , but found that it does not use circular list, as well as does not have option to set fixed maximum size.

dequeue中有一个max_size方法,但文档说这是容器由于系统或库实现限制而可能达到的最大大小。

There is a max_size method in dequeue, but documentation says "This is the maximum potential size the container can reach due to system or library implementation limitations."

是否还有其他容器可以使用?

Is there some other container I can use?

PS:我使用Visual C ++ 2010 express

PS : I am using Visual C++ 2010 express

推荐答案

没有标准的库容器直接做你想要的。但是,您应该查看 Boost的循环缓冲区容器。如果你不能使用Boost,你至少可以查看其源代码并重做它。

There is no standard library container that does what you want directly. However, you should take a look at Boost's Circular Buffer Container. If you can't use Boost, you can at least view its source and redo it.

这篇关于哪个STL C ++容器用于固定大小的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆