Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 627
mgr Avatar asked Dec 16 '22 23:12

mgr


1 Answers

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

like image 177
mkaes Avatar answered Jan 08 '23 19:01

mkaes