I've been trying to remember this and it's driving me crazy.
Basically, it's like a small array, of let's say size five, and as you add items it starts to fill up. When it's full, and you add a new item, the oldest one (first added) is removed.
You can access the values by something like variable[0], variable[1] etc, where variable [0] is the oldest value, and variable 4 the newest.
Any ideas on what this is called? Is it a standard C++ type, or did I just see it somewhere as a custom class?
Arrays are collections of data items that are of the same type, stored together in adjoining memory locations. Each data item is known as an “element.” Arrays are the most basic, fundamental data structure.
Arrays. An array is a structure of fixed-size, which can hold items of the same data type.
1) push() which adds an element to the top of stack. 2) pop() which removes an element from top of stack.
Boost Circular Buffer
http://www.boost.org/doc/libs/1_46_1/libs/circular_buffer/doc/circular_buffer.html
From the Boost docs:
// Create a circular buffer with a capacity for 3 integers.
boost::circular_buffer<int> cb(3);
// Insert some elements into the buffer.
cb.push_back(1);
cb.push_back(2);
cb.push_back(3);
int a = cb[0]; // a == 1
int b = cb[1]; // b == 2
int c = cb[2]; // c == 3
// The buffer is full now, pushing subsequent
// elements will overwrite the front-most elements.
cb.push_back(4); // Overwrite 1 with 4.
cb.push_back(5); // Overwrite 2 with 5.
// The buffer now contains 3, 4 and 5.
a = cb[0]; // a == 3
b = cb[1]; // b == 4
c = cb[2]; // c == 5
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