Skip navigation.

Tip: An STL-style circular buffer

circular_buffer.h: view highlighted, download

To support certain spectroscopy measurements with our Camera application[1] we need to record the last N samples in an AFM approach spectroscopy sweep[2]. Both the end of the series and the number of samples to retain are well-defined. This suggests the use of a circular buffer with a length of the desired number of samples. The Camera application is written in C++, more specifically Microsoft's Visual C++ 6 (VC6).

Looking for a free to use circular buffer class, I naturally found Boost.Circular Buffer[3]. However the boost::circular_buffer<> class template cannot be used with VC6. A further web search led me to the enlightening article in ACCU's Overload journal[4] by Pete Goodliffe, titled: STL-style Circular Buffers By Example[5][6]. Although the circular buffer class presented here also didn't compile with VC6, it's source code and supporting article encouraged me to adapt it so that it's also usable with VC6.

Notable changes with respect to the original code are:

Pete wrote a more recent series of Blog articles in which he also builds a circular buffer class, using pointers instead of indices this time[7].

Notes and References.
[1] Leiden University. Camera project for Scanning Probe Microsopy.
[2] JPK. A practical guide to AFM force spectroscopy and data analysis.(PDF, 0.37 MB)
[3] Boost.  boost::circular_buffer<>.
[4] ACCU. Overload and CVu Journals.
[5] Pete Goodliffe. ACCU Overload articles STL-style Circular Buffers By Example (part 1) and part 2
[6] Pete Goodliffe. Project page  C++ circular buffer library.
[7] Pete Goodliffe. Blog articles C++: An STL-like circular buffer (Part 1)
part 2, part 3, part 4, part 5, part 6, part 7, part 8, part 9, part 10, part 11

Page created 24 December 2011