Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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