Replies: 5 comments 4 replies
-
Hi MaJerie, Having a lock-free ring buffer is great, but having an off-by-one buffer size available to write creates unnecessary fragmentation and is unusable for anything that needs more then byte alignment (e.g. DMA transfers). Given that lwrb_get_free() returns len-1 and the buffer is always uint8_t, I don't see a way around this. My use case goes even further. I don't know my frame size until runtime, although I can guarantee my reads and writes will be multiples of the same denominator (e.g. if I write in blocks of 16, I know I can read in blocks of 16 as well). Wouldn't it be better to forego an additional byte in the in the lwrb structure and add a flag to indicate the buffer is full? |
Beta Was this translation helpful? Give feedback.
-
If we implement flag to indicate "buffer full", then original idea of the buffer is lost. This introduces second operation, (setting the flag, or clearing it) and same operation must be done between read and write. Then we need atomicity on multiple operations in a sequence, making stdatomic not really useful for the library, but we need to introduce rather platform specific way to lock the interrupts (or mutexes). If you know at runtime the frame size, you can make your array length of |
Beta Was this translation helpful? Give feedback.
-
Thank you for the new release, i just started a new project with it :) |
Beta Was this translation helpful? Give feedback.
-
Hi MaJerie, Maybe a bit out of scope as lwrb is a C library, but I had problem with using the library in a cubeIDE C++ project containing both C and C++ source code, as there was a conflict with .cpp files and <stdatomic.h>. Finally, following this post , modified lwrb.h as below :
Thank you for the amazing libraries, fast, clearly written and well documented as well |
Beta Was this translation helpful? Give feedback.
-
Be careful doing this. |
Beta Was this translation helpful? Give feedback.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions