MaJerle/lwrb
FreeLightweight generic ring buffer manager library
About MaJerle/lwrb
lwrb is a lightweight, generic FIFO ring buffer manager library written in C (C11). It provides a platform-independent implementation with no dynamic memory allocation, using static arrays instead. The library is optimized for performance by using memory copy operations instead of loops for reading and writing data. It is thread-safe and interrupt-safe when used as a pipe with single writer and single reader, provided the CPU has atomic size_t operations (e.g., ARM Cortex-M). For smaller architectures like AVR, atomic protection is required. lwrb supports DMA transfers with zero-copy overhead, data peek/skip for read, advance for write, and event notifications. It is released under the MIT license and is suitable for embedded systems, real-time applications, and any scenario requiring efficient FIFO buffering.
Key Features
Pros & Cons
- Lightweight and platform-independent design
- No dynamic memory allocation reduces risk of fragmentation and allocation failures
- Optimized memory copy improves throughput compared to loop-based implementations
- Thread-safe and interrupt-safe for single-writer single-reader scenarios
- Supports DMA transfers with zero-copy overhead
- Flexible operations: peek, skip, advance, event notifications
- MIT license allows unrestricted use in commercial projects
- Thread-safety limited to single-writer single-reader configurations; multi-writer or multi-reader requires external synchronization
- Requires atomic protection on architectures where size_t read/write is not atomic (e.g., AVR)
- FIFO only; no support for LIFO or priority-based buffer ordering
- Not a general-purpose data structure; specialized for ring buffer management