I am using an STL deque structure and at each iteration of my algorithm, I am removing n
elements from the front and adding n
elements at the end. So, basically, my deque size never changes and I am doing millions of iterations.
Is there a way to ensure that the memory size does not change (or at least does not go down) during its lifetime? Perhaps due to the underlying implementation of the deque perhaps this is unavoidable but I wanted to make sure.
std::deque
doesn't implement this, and your scenario will most certainly require allocations and deallocations frequently. Have a look at Boost.Circular Buffer - If you don't like boost, or want to implement your own circular buffer, the documentation is still worth reading. It explains how such a buffer works. It can be implemented withstd::vector
pretty easily. – leemesvector
will be the most efficient. Don't start withdeque
. – Mark Ransom