mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
Circular Buffer

A circular buffer class. More...

A circular buffer class.

Three options for the circular buffer are provided, each inheriting the same underlying interface. The choices vary the way in which the wrapping is handled at the beginning and end of the storage. These are:

Benchmarks are clear that circularBufferIndex is fastest for sequential acceess, e.g. one element after the other in sequential order, by something like 30%. For random access circularBufferBranch is possibly slightly faster, but not enough tests were performed to be conclusive.

circularBufferMod is always much slower due to use of the % operator. Don't use this for real work.

The memory overhead of circularBufferIndex is 3*maxEntries*sizeof(indexT), where maxEntries is the maximum length of the buffer, and indexT is the type used for indexing and sizes. The factor of 3 enables negative offsets, i.e. for traversal in reverse.

Note
circularBufferIndex will not properly wrap until it is full. Attempts to access wrapped entries prior to inserting maxEntries entries will segfault.
Todo:

perform circular buffer testing on an isolated core, with one test per executable

implement a circular buffer with fixed power-of-two size to test & modulo

Classes

class  mx::sigproc::circularBufferBase< _derivedT, _storedT, _indexT >
 CRTP base class for all circular buffers, providing the underlying memory management and accessors. More...
 
class  mx::sigproc::circularBufferBranch< _storedT, _indexT >
 Circular buffer which wraps with an if statement (branching) [faster than mod, less memory than index]. More...
 
class  mx::sigproc::circularBufferMod< _storedT, _indexT >
 Circular buffer which wraps with the mod opoerator [very slow]. More...
 
class  mx::sigproc::circularBufferIndex< _storedT, _indexT >
 Circular buffer which wraps with a pre-populated indices array [generally fastest]. More...