-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing a single data fills the buffer #58
Comments
Any access beyond the current buffer bounds is a violation of the contract and assuming anything about the buffer internal state is a usage error. In other words, accessing positions beyond 0 is an error, you are making assumptions on how the buffer operates on its internals. It wasn't arising in the previous version because the buffer wasn't protecting its internal state properly: now the buffer does that better and it only allows you to access populated positions. If you have only one element it doesn't matter what's the index you provide, you will always get that single item. |
Another way to describe the behaviour, if you want to print the buffer contents you should only print the items between position See the two for-loops examples at https://github.com/rlogiacco/CircularBuffer#automatic-optimization and the code at CircularBuffer/examples/Test/Test.ino Lines 6 to 27 in cf4ded9
If you want to inspect the internals for debugging reasons, you can enable debugging and use the two #define CIRCULAR_BUFFER_DEBUG
#include <CircularBuffer.h>
CircularBuffer<long, 6> buffer; And then you can call |
You're right but for a simple user like me it would be more comfortable to indicate the data is not available (return "nan") without the need to add additional conditions in a for cycle. |
I’m not aware of the existence of such type.
I would throw an exception, but that’s also unavailable: I’m open to
suggestions which can be safely and soundly I mplemented on a
microcontroller.
Il giorno lun 6 dic 2021 alle 22:42 pkrssy ***@***.***> ha
scritto:
… You're right but for a simple user like me it would be more comfortable to
indicate the data is not available (return "nan") without the need to add
additional conditions in a for cycle.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABQWMLZ5BA4W54F65IIPD3UPUU5FANCNFSM5JMRDUFA>
.
|
v1.3.3
If a single data is written into the newly created buffer, buffer.size() reports one but all the other elements of the buffer is filled with the data.
Result:
The behavior can not be experienced in v1.3.0
The text was updated successfully, but these errors were encountered: