|
Boost : |
From: AlisdairM - BTInternet (AlisdairM_at_[hidden])
Date: 2000-11-13 16:37:23
> -----Original Message-----
> From: James M. Curran [mailto:jamescurran_at_[hidden]]
> This could be accomplished with a standard vector, and a "circular
> iterator" which loops back to the beginning when it reachs the end.
> I wrote an article about it some time ago
> http://www.noveltheory.com/iterators/Iterator_N1.htm
Thanks for the reference. Although that doesn't quite do what I was
proposing, it will be a good starting point, as the majority of the work
will be in the iterators. I think your references within the article to a
circular buffer is more likely to be on the mark, although I see they are
still left as an exercise for the reader <g>
A circular iterator has a beginning and no end, whereas I am proposing a
container where objects have a limited lifetime, long enough until they are
pushed out by new arrivals. As such, it should always be possible to know
when you have iterated once through the entire container.
By pre-allocating the container of a fixed size up front, it should be
possible to avoid some memory-fragmentation issues (perhaps relevant in 24-7
running). There are also cirumstances (typically data-logging) where you
want to efficiently add elements to a container, and aren't as worried about
the manner of their exit. However, it may still be useful to iterate over
some or all of the elements in the container, for instance to plot a graph
or generate a report.
I don't think it is possible to implement this entirely in the iterator,
although if I am missing something obvious I will be happy to be corrected.
As you suggest, the container is likely to be based around a vector
internally.
If you have a reference to a public-domain, fleshed-out circular buffer
implementation I would be grateful to see it. Failing that, if you are
interested in critiquing one I can provide some code!
Given the general silence on the topic I am assuming that it is well covered
elsewhere, or not of interest to boost. If it is simply a matter of me not
uploading code to peruse could someone give me a kick in the right
direction, but the docs said canvas for opinion before posting, and it seems
pretty quiet right now.
Thanks for reading
AlisdairM
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk