[Qt-interest] circular buffer container
Andre Somers
andre at familiesomers.nl
Fri Apr 23 14:30:31 CEST 2010
On 23-4-2010 11:38, Sean Harmer wrote:
> Hi All,
>
> Just in case anybody is doing data acquisition/logging type work, I have
> just submitted a QCircularBuffer class as a merge request to gitorious.
> The merge request is here:
>
> http://qt.gitorious.org/qt/qt/merge_requests/2364
>
> This is my first merge request of any size so I would really appreciate
> any feedback that you can give on API, implementation and documentation
> omissions etc.
>
> Many thanks in advance,
>
>
First of all, I like the idea of adding a circular buffer to Qt. Very nice.
I did wonder when I glanced over your implementation: would it not have
been much easier to implement this based on one of the exising container
classes instead? That would result, I think, in an easier to maintain
solution, as you have to do the heavy lifting of memory operations only
once. This is how QQueue and QStack are implemented: a bit of sugar on
top of QList and QVector respectively. To me, it seems like a circular
buffer is not much more than a QQueue with a limited number of items in
it, right? Is there a reason you chose a from-scratch aproach?
I have created similar datastructures myself (based on the existing Qt
datastructures) in the past. I found that often there are other criteria
that are relevant than just what the oldest bit of data is. Wouldn't it
make your data structure more versatile if you would provide an optional
way to determine which item to drop first?
Let me give you an example: A long time ago, I implemented a system to
store measurements of the windvector for a flight computer for glider
pilots. These measurements had different quality, and we had an
indication for that quality. Because of memory constraints, we only kept
a limited number of such measurements in memory to determine the current
wind. The selection of what item to drop, was a function of that quality
*and* the age of the measurement. I can image similar constraints in
other applications. You talk about data logging or visualisation
applications in your merge request. Would also there not only the age of
a piece of data, but also it's importance play a role? For instance, say
you want to keep a log of events on a server. These come in the form of
errors, severe warnings, warnings and information messages. Personally,
I would build the application in a way that it would keep te errors and
the severe warnings (perhaps detections of attemted server breakins?)
longer in the displayed log than the informational and low-importantance
warnings.
However, such a feature may be out of scope :-)
André
- just another Qt user
More information about the Qt-interest-old
mailing list