Small library for using circular buffers

Dependents:   CircularBufferExample

You are viewing an older revision! See the latest version

Homepage

This library provides circular buffers. The main difference with other circular buffer libraries is that it does not use dynamic memory allocation for storing data. Instead, the buffer is allocated statically.

Example

#include "mbed.h"
#include "CircularBuffer.h"

int main()
{
    CircularBuffer<16> buffer;
    uint32_t n = buffer.write((uint8_t*)"Hello World !", strlen("Hello World !"));
    printf("wrote %d bytes\n", n);
    char str[10];
    n = buffer.read((uint8_t*)str, 5);
    str[n] = '\0';
    printf("str=%s\n", str);                // prints:Hello
    buffer.read((uint8_t*)str, 1);          // discard space
    n = buffer.read((uint8_t*)str, 7);
    str[n] = '\0';
    printf("str=%s\n", str);                // prints:World !
    
    return 0;
}

Three types of buffers already exist :

SmallCircularBuffer          // 32 bytes 
MediumCircularBuffer      // 128 bytes
BigCircularBuffer             // 512 bytes

All wikipages