
AMDG Daniele Barzotti wrote:
in the introductory example I see this:
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
and I would ask why the 4 and 5 are in the 2nd and 3th position instead of 1st and 2nd respectively.
I thought that it worked in the following way:
1 2 3 1 2 3 1 2 3 [A][B][C] -> push_back(D) -> [D][B][C] -> push_back(E) -> [D][E][C]
I need a circular buffer for buffering network data and I need that the old data is replaced but doesn't change its position..
What actually happens is something like this: 1 2 3 3 1 2 2 3 1 [A][B][C] -> push_back(D) -> [D][B][C] -> push_back(E) -> [D][E][C] The indexes are adjusted, but the physical locations of the elements don't change. In Christ, Steven Watanabe