ahills60 / CircularBuffer

A basic circular buffer demo written in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Circular Buffer

This is a demonstration of a circular buffer of time-series data with the ability to offload the data whenever it's necessary. This demonstration is written in C and the circular buffer can be moved to other projects if required.

This circular buffer has a basic optimisation of pre-computing pointer indices to avoid the modulo operation which can be useful for implementations that:

  • Add data many times.
  • Extract the contents of the buffer many times.
  • Do not have access to hardware support for faster modulo evaluations without the need for if statements.

Note that this workaround requires more memory, particular for large arrays. It may therefore be necessary to consider the impact of memory versus modulo evaluation in the intended application of this circular buffer.

This implementation provides a function (changeSize) to resize the buffer on demand. A larger parent buffer is used to ensure that enlarging a buffer doesn't result in zero values, but returns historical data.

About

A basic circular buffer demo written in C

License:MIT License


Languages

Language:C 91.0%Language:CMake 5.8%Language:Makefile 3.1%