-
Notifications
You must be signed in to change notification settings - Fork 14
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
Simplify API #57
Simplify API #57
Conversation
/// The provided slots are *not* automatically made available | ||
/// to be read by the [`Consumer`]. | ||
/// This has to be explicitly done by calling [`WriteChunk::commit()`], | ||
/// [`WriteChunk::commit_iterated()`] or [`WriteChunk::commit_all()`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if commit
, commit_iterated()
or commit_all
is not called? My guess is that the consumer cannot see the items that have been written and that the items written can be overwritten by calling "push()" (or similar) again, which would cause them to be leaked. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly.
I've just added a commit (7bb6e5d) that hopefully clarifies that.
I like the removal of There's some asymmetry between the "normal" API were items are moved into and out of the ring buffer and the "chunked" API where the user of the API is given access (via Thinking about it this way, I would suggest to consider replacing the "chunked" API by some other methods:
Just my two cents, this might actually not be a good idea after all. I'm happy that somebody is actually maintaining this crate in his spare time, so I really can't complain. Edit: I meant moving elements from ring buffer into slice. |
Thanks for your suggestions @PieterPenninckx, I very much appreciate this!
Well, yes, for me the main usage is with chunks of But items don't actually have to be
Yes indeed, in this case multiple An extension for batch-moving has already been requested in #56.
Yes, but wouldn't it be strange to return a writable slice for a read operation? And the I think it would be better to provide a separate way for batch-moving.
I wouldn't want to replace the slice functions, because they allow very efficient The iterator API could probably be replaced, though.
Yeah, that would be possible, let's discuss this in #56.
I'm not sure whether this is "fundamental" enough to deserve its own method. I've provided an example for how to implement this as a user in: https://docs.rs/rtrb/0.1.4/rtrb/#common-access-patterns This also shows that there are multiple possible behaviors. Which one would we choose for an "official" method? |
I proposed a method to copy all elements from a slice into the ring buffer on the producer side and a method to copy all elements from the ring buffer into a slice on the consumer side. That would be do exactly the efficient
I would go for the Reading your comments, I'm not so sure anymore about the design that I proposed. The reason is that, when it comes to slices, it only allows for the slice -> ring buffer copying and ring buffer -> slice moving, but maybe there are other things you can do with slices and that are not possible with the design that I proposed. |
I thought there would be also Anyway, I have another use case for the 2-slices API: using fixed-size chunks (which led me to create #50 and #52 and finally this very PR). Since I'm not planning to introduce additional API for fixed-size chunks anymore, I'll have to use the existing chunks-and-slices API, and for that I need direct access to the first of the two slices. And apart from that, I just have the feeling that the two-slices API is the "classic" low-level representation of SPSC ring buffers. I would like to go as low-level as possible (without exposing raw pointers, though).
Yes, that's certainly possible, I just didn't want to show too much I'm using the Lines 1471 to 1489 in 272f9d7
I haven't needed it myself so far, but I'm starting to realize that exposing this function would be indeed helpful, because then users don't need to use And then I could use that new function to implement
I guess you mean using the I think this would be less efficient for the
That's true, it's not possible with the current API, but I think this could be added as separate API as discussed in #56. The problem with "moving non- The
As I mentioned above, there's my fixed-chunks use case. Apart from that I don't know any concrete and real use cases, but there is at least one theoretical use case: You want to "peek" at several items and only later decide whether you actually want to consume them or not. |
I've just created a possible implementation of the discussed slice API: #66. |
This is a different potential way to go (compared to #52), which reduces the API surface instead of extending it.
This is a breaking change (mostly just removing
.split()
).Auto-generated docs as ZIP file: https://github.com/mgeier/rtrb/suites/3125739092/artifacts/71657611.