-
Notifications
You must be signed in to change notification settings - Fork 4
Software Circular Buffers
Pascal Roobrouck edited this page Jan 20, 2017
·
4 revisions
In the Mooov controller a number of buffers are used, the most important one being the motionBuffer. All buffers are implemented with the same scheme using a:
- head : index of the oldest item in the buffer
- level : how many items are in the buffer
- length : how many items can the buffer hold
I prefer this mechanism over a 'head' and 'tail' pointer, as I find the math more logical and simple.
- Read from bufferHead
- Write to (bufferHead + bufferLevel) % bufferLength
- Read from (bufferHead + bufferLevel -1) % bufferLength
- Write to (bufferHead + bufferLevel) % bufferLength
empty buffer? test for (bufferLevel == 0)
full buffer? test for (bufferLevel == bufferLength)
Documentation Wiki TOC