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.
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.
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 : I am using Visual C++ 2010 express
Types of STL Container in C++ In C++, there are generally 3 kinds of STL containers: Sequential Containers. Associative Containers. Unordered Associative Containers.
Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity). Map: Collection of key-value pairs, sorted by keys, keys are unique (class template).
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.
There's boost::circular_buffer. Then there's
std::vector<T> vec(size);
vec[i % size] = newelem;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With