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
Allow reclaiming the current allocation #686
base: master
Are you sure you want to change the base?
Conversation
This is a draft to get some comments on whether such an API addition would be acceptable |
This is based on tokio-rs#680, where it was noted that it is hard to use BytesMut without additional allocations in some circumstances.
This looks a lot like |
I think it is hard to know what the original capacity is, generally, as it could've been influenced by lots of hidden operations before. |
That's true, but presumably you know how much data you'll need to reserve regardless (otherwise dynamic allocation seems like the best strategy). So it doesn't particularly matter if you can reclaim the entire buffer, only if it can fit the data you're receiving. Or am I missing the point here?
Very cheap relative to what though? Based on your description in #680, your only other alternative would be to allocate anyway, right? And that's definitely expensive relative to moving bytes. If that's not the alternative, what is? |
My usecase is that I have a couple of |
This is based on #680, where it was noted that it is hard to use BytesMut without additional allocations in some circumstances.