jnk0le / Ring-Buffer

simple C++11 ring buffer implementation, allocated and evaluated at compile time
MIT License
380 stars 64 forks source link

"no wasted slots" is only true if you need power of 2 size #4

Closed mratsim closed 5 years ago

mratsim commented 5 years ago

Assuming you need 10 slots in the ring-buffer, your implementation will waste 6 slots to be at a power of 2 while the traditional one will only waste only one slot.

This might be a deal-breaker on resource restricted device as such I would change the description from

  • pure C++11, no OS dependency
  • no exceptions, RTTI, virtual functions and dynamic memory allocation
  • designed for compile time (static) allocation and type evaluation
  • no wasted slots
  • lock and wait free SPSC operation
  • underrun and overrun checks in insert/remove functions
  • highly efficient on most microcontroller architectures (nearly equal performance as in 'wasted-slot' implemetation)

to

  • pure C++11, no OS dependency
  • no exceptions, RTTI, virtual functions and dynamic memory allocation
  • designed for compile time (static) allocation and type evaluation
  • no wasted slots if you use power of 2 sizes
  • lock and wait free SPSC operation
  • underrun and overrun checks in insert/remove functions
  • highly efficient on most microcontroller architectures (nearly equal performance as in 'wasted-slot' implemetation)