[Development] New circular buffer container for Qt5

Sean Harmer sh at theharmers.co.uk
Fri Oct 28 15:11:08 CEST 2011


I would like to introduce a new generic container class to Qt, 
QCircularBuffer. This email is to see if there are any objections to doing so.

This class is similar to QVector but it provides circular semantics. For 
example, appending to an already full circular buffer will overwrite the 
oldest item i.e. it forms a kind of LRU cache. The API is essentially a 
Qt'ified version of the boost::circular_buffer [1] API so hopefully people 
will find it simple to use.

This type of container is very useful for logging or data 
acquisition/visualisation applications as it provides a static memory profile 
and fast performance for adding new data to the container.

Appending and prepending are always O(1) operations which fills in a gap in 
the performance characteristics offered by the existing Qt containers.

It tries to be smart when modifying the contents of the container by depending 
upon the type of item being stored. Copying is also kept to a minimum to 
improve performance (see the insert() and remove()) functions.

It is a template class so no extra code is generated in the Qt shared 

It is fairly trivial to use this class as the underlying container of a 
bounded buffer that can be used with the producer-consumer pattern. I am 
willing to also contribute code for this to the Qt project if people think it 
would be useful.

I have already used this container in several applications and it comes with 
comprehensive documentation and an auto test.

Kind regards,


[1] -  

More information about the Development mailing list