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

Add an Arc-/Rc-based reader #294

Closed
fitzgen opened this issue Apr 28, 2018 · 6 comments
Closed

Add an Arc-/Rc-based reader #294

fitzgen opened this issue Apr 28, 2018 · 6 comments

Comments

@fitzgen
Copy link
Member

fitzgen commented Apr 28, 2018

https://www.reddit.com/r/rust/comments/8fcm5i/a_sampling_cpu_profiler_for_linux_written_in_rust/dy2mm2a/?context=3

  1. The EndianBuf does take a lifetime, which is somewhat annoying when you want to just mmap a file and you don't want to permanently leak it. What I did here (for now) is I've put everything into one structure (FrameDescriptions in frame_descriptions.rs), put the mmaped data in an Arc, wrapped everything in mem::ManuallyDrop, set the lifetimes to 'static and used mem::transmute quite liberally.

I think we don't want to just make EndianBuf but with replacing the &[u8] with Arc<[u8]>, because that means that slicing or splitting the reader would require copying the data. We want something like (start, end, Arc<[u8]>) and have slicing/splitting just change the start and end indices and bump the ref count.

cc @koute

@philipc
Copy link
Collaborator

philipc commented Apr 28, 2018

I'm going to look into using https://crates.io/crates/bytes (or at least use its ideas).

@fitzgen
Copy link
Member Author

fitzgen commented Apr 28, 2018

@fitzgen
Copy link
Member Author

fitzgen commented Apr 28, 2018

It seems that it is similar to the (start, end, Arc<[u8]>) representation but with variants for static buffers (I don't think this is too relevant for our use case) and for inlining small buffers directly into the handle instead of putting them behind a pointer.

@koute
Copy link
Contributor

koute commented Apr 28, 2018

If I'll mmap a file I'll have some Arc<T> instead of an Arc<[u8]>, where T is going to be an arbitrary type which will control the lifetime of the mmap. So it'd be the best to allow the user to use a custom type and constraint T to be T: Deref<[u8]> or T: bytes::Buf or something along these lines.

@fitzgen
Copy link
Member Author

fitzgen commented Apr 28, 2018

SGTM!

@fitzgen
Copy link
Member Author

fitzgen commented Apr 28, 2018

Some initial ground work being laid in #295

fitzgen added a commit to fitzgen/gimli that referenced this issue May 11, 2018
An easy way to define a custom `Reader` implementation with a reference to a
generic buffer of bytes and an associated endianity.

Fix gimli-rs#294
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants