Skip to content
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

Maybe use Bytes within AlignedBuffer #112

Closed
JackKelly opened this issue Mar 25, 2024 · 2 comments
Closed

Maybe use Bytes within AlignedBuffer #112

JackKelly opened this issue Mar 25, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@JackKelly
Copy link
Owner

See this code sketch for how to create a Bytes from an aligned buffer.

This will get easier if my PR to Bytes gets accepted: tokio-rs/bytes#684

Why?

Once the operating system has written into these buffers, I'd love to wrap the buffer in Bytes so I can:

  • share read-only access to multiple "owned" slices of the buffer.
  • match existing API's like object_store's API which returns Bytes.
@JackKelly JackKelly added the enhancement New feature or request label Mar 25, 2024
@JackKelly JackKelly moved this to Todo in light-speed-io Mar 25, 2024
@JackKelly
Copy link
Owner Author

JackKelly commented Mar 26, 2024

Conclusion: Can't use Bytes (as it stands today)

Actually, as Bytes stands today, I don't think it's possible to safely wrap an aligned buffer in Bytes. The problem is that dealloc needs to know the layout, and I can't think of a way to tell Bytes.vtable.drop about the layout (it always assumes the layout is 1).

One day, Bytes might implement a new vtable API: tokio-rs/bytes#437

Until that day, I suspect the easiest solution will be to implement a minimal set of Bytes-like behaviour in my AlignedBuffer crate

@JackKelly
Copy link
Owner Author

I've submitted a detailed write-up of my use-case to the Bytes issue discussing the new vtable API: tokio-rs/bytes#437 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

1 participant