Boost logo

Boost :

From: jga_at_[hidden]
Date: 2003-06-06 17:08:38

Hi Nigel!

Quoting Nigel Stewart <nigels_at_[hidden]>:

> Jan,
> I'm looking forward to the opportunity of having a close look
> at your cyclic_buffer. But for now, a few perhaps shallow
> comments...
> 1. How about push_front()? (in std::list style)
> And pop_front()?
> For the sake of generality.
Imagine you have a cyclic buffer which is full. When you add (push_back or
insert) a new item into this buffer the first (oldest) item will be removed. I
want to emphasize the "oldest". So if you want to push_front an item you want to
add the oldest one. But as soon as you add it the item will be removed because
it is the oltest item in the buffer. The buffer's content won't change. (The
same is valid for inserting at the beginning of the cyclic buffer.) This is the
reason why I didn't encompassed push_front in the implementation.

If there is no push_front then it is not logical to have pop_front. You can use
erase(begin) instead.

> The vague concept I have in mind is some kind
> of sliding window algorithm that could be moving
> either left or right, using a circular buffer as
> a cache. (Currently pondering a 2D version of a
> circular buffer, anyone come across such a beast?)
> 2. How about reserve(..) and resize(..)?
> Shouldn't change_capacity be called reserve, like vector?
If you look more closely at the documentation you will find out that
change_capacity is different from reserve. The capacity can be also decreased;
by reserve not.

> Shouldn't max_size be called capacity, like vector?
max_size in the vector is the largest possible size, not the reserved capacity.

> One context I which I've made happy use of a circular
> buffer is for storing history in the form of a 3D
> trail for moving particles. It's handy to allow the
> GUI to adjust the size of trails dynamically.
> Semantics of resize should probably follow vector:
> 1. The capacity is implicitly adjusted to fit the
> requested size. (Optional to explicitly manage
> capacity in addition to size)
> 2. Items are lost from the end if the container is
> to be shrunk.
Are you sure you want to lost the items at the end ? Not at the beginning (the
oldest) ?
BTW if you change_capacity in order to shrunk the container the oldest items
will be removed.

> (Oops, just noticed that resize is in one part of
> the documentation, but not the non-doxygen page).
Thank you for this!

> For your reference, my somewhat more modest circular buffer:
> I am new to boost, but liking it very, very much...
> Cheers,
> Nigel Stewart
> > The cyclic buffer implementation and documentation ( can
> be
> > found at:
> >
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at