MaJerle/lwrb logo

MaJerle/lwrb

Free

Lightweight generic ring buffer manager library

FreeFree tier
Type
Open Source

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

Written in C (C11), compatible with size_t for size data types
FIFO (First In First Out) buffer implementation
No dynamic memory allocation; data stored in static array
Uses optimized memory copy instead of loops for read/write
Thread-safe when used as pipe with single write and single read entries, given atomic size_t operations
Interrupt-safe under same conditions
Suitable for DMA transfers with zero-copy overhead between buffer and application memory
Supports data peek, skip for read, and advance for write
Event notification support
MIT license

Pros & Cons

Pros
  • 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
Cons
  • 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

Best For

FIFO buffer for embedded systems with constrained resourcesReal-time data streaming in microcontroller applicationsDMA-based data transfer pipelinesThread-safe communication between tasks in RTOSInterrupt-safe logging or data collection in bare-metal systemsEvent-driven buffer management

FAQ

Does lwrb use dynamic memory allocation?
No, lwrb does not use dynamic memory allocation. It operates on a user-provided static array, making it suitable for environments where malloc is unavailable or undesirable.
Is lwrb thread-safe?
Yes, under specific conditions. lwrb is thread-safe when used as a pipe with single write and single read entries, and when the CPU's read/write operation for size_t is a single instruction (e.g., ARM Cortex-M). For other architectures, external atomic protection is needed.
What license is lwrb released under?
lwrb is released under the MIT license, which permits free use, modification, and distribution in both open-source and commercial projects.
Can lwrb be used with DMA transfers?
Yes, lwrb is suitable for DMA transfers with zero-copy overhead between the buffer and application memory, enabling efficient data movement in embedded systems.