StephanvanSchaik / mmap-rs

A cross-platform and safe Rust API to create and manage memory mappings in the virtual address space of the calling process.
Apache License 2.0
59 stars 17 forks source link

Reference files when creating memory mappings rather than taking ownership #17

Closed StephanvanSchaik closed 1 year ago

StephanvanSchaik commented 1 year ago

In version 0.5 and older of mmap-rs, Mmap was designed to take ownership of the File. Part of the reason to do this was to ensure Mmap::flush() would be synchronous on Microsoft Windows, since it needs to call FlushFileBuffers() on the file handle.

However, this complicates some planned API changes to implement Mmap::from_raw() and the ability to split memory mappings into multiple memory mappings.

This PR removes Mmap::file() that returns a reference to the File owned by the memory mapping, and changes MmapOptions to work with a reference of the file, rather than taking ownership.

Since this breaks the behavior of Mmap::flush(), the comment has been updated to inform the requirement of having to call File::sync_all() to ensure it is synchronous and actually flushes the file metadata on Microsoft Windows.