From FOLDOC, the Free On-Line Dictionary Of Computing (

<programming> An area of memory used to store a continuous stream of data by starting again at the beginning of the buffer after reaching the end. A circular buffer is usually written by one process and read by another. Separate read and write pointers are maintained. These are not allowed to pass each other otherwise either unread data would be overwritten or invalid data would be read.

For example, to initialise a circular buffer (a.k.a. rolling buffer), which is 20 words long starting at address 0x3210, pseudo-code might look like this:

#define BufferBase (0x3210)
#define BufferSize (20)
ReadPointer := 0
WritePointer := 0
Empty := true

To add to the buffer:

if ((WritePointer = ReadPointer) && (Empty = false)) {
  ERROR ("Buffer overflow")
*(BufferBase + WritePointer) := WriteData
WritePointer := ((WritePointer + 1) mod BufferSize)
Empty := false

To read from the buffer:

if (Empty = true) {
  ERROR ("Buffer underflow")
ReadData := *(BufferBase + ReadPointer)
ReadPointer := ((ReadPointer + 1) mod BufferSize)
if (ReadPointer = WritePointer) {
  Empty := true

Log in or register to write something here or to contact authors.