|
Boost Users : |
Subject: [Boost-users] [circular_buffer] About overwriting elements
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2010-04-16 09:31:31
Hi,
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..
Thanks,
Daniele.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net