|
Boost Users : |
Subject: Re: [Boost-users] A need for a complex pool type container
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-02-18 18:16:57
On Wed, Feb 18, 2009 at 17:57, Robert Dailey <rcdailey_at_[hidden]> wrote:
>
> I insert new events into existing buckets anywhere in the container, it does
> not necessarily have to be from the back. I always remove items from the
> front since they are processed linearly.
>
> One can kind of think of this as a std::deque< std::vector<> >, but the
> containing deque would need to be given a fixed size of 100 (as in the
> example above). The tricky part is shifting all of the "buckets" (the
> buckets in this case would be the inner-vector objects) forward when
> something from the front is removed. The key here is that I do not want to
> call pop_front() each time a bucket is processed because I want to avoid
> constant new/delete operations since insertion and removal will be happening
> quite frequently.
>
> I'm not sure what the best approach to solving this problem is. I'm hoping
> someone in the community will be able to suggest a way in which boost can
> easily solve this problem. Thanks to everyone for taking the time to read
> this.
>
Perhaps this?
boost::circular_buffer<vector<T> > schedule(100);
Then you could use
schedule.rotate(schedule.begin()+1);
to move to the next bucket, which should (in steady-state) avoid
reallocation of the container or the buckets, since you never actually
destruct or copy the vectors.
http://www.boost.org/doc/libs/1_38_0/libs/circular_buffer/doc/circular_buffer.html
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