Boost logo

Boost Users :

Subject: Re: [Boost-users] circular_buffer, debug and invalid iterator checking
From: Anthony Foglia (AFoglia_at_[hidden])
Date: 2010-11-08 10:29:44


Nigel Stewart wrote:
>> maximum number, or some condition on the stored data (e.g. the sum must be
>> below a threshold) is met. So I figured I'd store the data in a circular
>> buffer, and push new data onto the front, and store my own
>> iterator into it to use as the end.
>
> Anthony,
>
> Would it be viable to simply erase the remaining items, rather than
> storing the iterator my_end?

I realized that after I pressed send, but I'm storing my iterators as
const_iterators because I wasn't expecting to need to change the buffer
with them.

>>From an efficiency point of view it seems like the sum could be
> updated for each push, and then iteration over the items that
> need removing (from the end), rather than re-traversing the
> items at the front that need to be kept.

My actual problem is more complicated, with not just one iterator, but
three, and not just ints, but a struct with multiple data members
(though my code is only currently interested in one). The total number
of items in the buffer is only 12, so the bookkeeping of three sums
probably not worth the gain in speed in my situation. (This code is not
the bottleneck.)

-- 
Anthony Foglia
Princeton Consultants
(609) 987-8787 x233

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