Proper data structure to store last n elements in C++

c++, data-structures

Solution

Sounds as if you want a circular buffer that overrides the values. Take a look at boost for an example.

Problem

I need to store last n time values and I'm using a vector for this. I can do this and it works, but my question is, at long run, the vector would fill up and I might run out of memory right?. I'm using a stl vector of floats. To be more clear : I'm pushing back time values from another process and i ONLY need the last 5 time values. How can I do this efficiently, without letting the vector fill up and eventually run out of memory?

Original source