-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat(byteview): Add non-consuming mmap constructor #448
Conversation
This adds constructor to mmap a File into a ByteView without consuming the file object.
// Ensure we can still read from the the file after mmapping and deleting it on disk. | ||
let mut buf = Vec::new(); | ||
file.rewind()?; | ||
file.read_to_end(&mut buf)?; |
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.
So does mmap-ing keep the FD alive? Might be interesting to explicitly drop(file)
after this, and see that the view still works (and holds on to the FD).
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.
Yes, mmap only uses the fd to figure out what to map, afterwards you can close it or do whatever you like to it. I added the explicit drop to make it even more obvious
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.
Yes,
That "yes" is not really true as the rest of the sentence explains 😄 mmap does not use the fd at all other than finding the right file to map. so it doesn't keep the FD alive either.
Since |
Yeah, the naming is not ideal and I'm open to better suggestions. I think API-wise we can't really change the behaviour of the existing method or remove it right away though. |
To be honest, I'm not overly concerned about the only naming difference being a single |
This adds constructor to mmap a File into a ByteView without consuming
the file object.