You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really like this library due to its simplicity. However, one thing its missing for my use case is support for private, copy-on-write mappings.
In other words, I want to be able to map a file and edit the mapping, but not have edits persisted to the underlying file, which is typically implemented using private, copy-on-write pages under the covers.
On Windows this means passing FILE_MAP_COPY to MapViewOfFile, instead of FILE_MAP_READ or FILE_MAP_WRITE. I believe the MSDN documentation is incorrect for this, as it says FILE_MAP_COPY should be ORed with FILE_MAP_READ, FILE_MAP_WRITE or FILE_MAP_ALL_ACCESS. This stackoverflow post indicates that this is wrong, and FILE_MAP_COPY should just be passed on its own. This is what boost.iostreams does.
On Linux, this means passing MAP_PRIVATE via flags to mmap. It's not entirely clear to me what difference PROT_READ vs. PROT_WRITE makes if MAP_PRIVATE is passed via flags.
The simplest way to support this seems to be to add a new access_mode value - maybe copy, copy_on_write, or private. FILE_MAP_COPY should be passed to MapViewOfFile on Windows, and PROT_READ and MAP_PRIVATE should be passed to mmap on Linux. However, this depends on whether I've overlooked some important subtlety on Linux when PROT_READ vs PROT_WRITE is passed to mmap with MAP_PRIVATE. If so, perhaps a new mapping_mode enum with shared and private values would be desirable.
I'm happy to take a stab at this myself if you can give me your thoughts on what the interface for this should be.
The text was updated successfully, but these errors were encountered:
@jimmehc I'm glad to hear you like this library! I'd be more than happy for you to send a PR :)
I think what you propose--adding an entry to access_mode--is indeed the simplest way, and how I would attempt to do this as well (due in large part to the pain of adding another template parameter to the class and thus having to update all out-of-class definitions 😀).
Moreover, having a separate mapping_mode parameter would allow for a read-only private mapping (with the combination of access_mode::read and mapping_mode::private), of which there is probably little use, but please correct me if I'm wrong.
I really like this library due to its simplicity. However, one thing its missing for my use case is support for private, copy-on-write mappings.
In other words, I want to be able to map a file and edit the mapping, but not have edits persisted to the underlying file, which is typically implemented using private, copy-on-write pages under the covers.
On Windows this means passing
FILE_MAP_COPY
toMapViewOfFile
, instead ofFILE_MAP_READ
orFILE_MAP_WRITE
. I believe the MSDN documentation is incorrect for this, as it saysFILE_MAP_COPY
should be ORed withFILE_MAP_READ
,FILE_MAP_WRITE
orFILE_MAP_ALL_ACCESS
. This stackoverflow post indicates that this is wrong, andFILE_MAP_COPY
should just be passed on its own. This is what boost.iostreams does.On Linux, this means passing
MAP_PRIVATE
viaflags
tommap
. It's not entirely clear to me what differencePROT_READ
vs.PROT_WRITE
makes ifMAP_PRIVATE
is passed viaflags
.The simplest way to support this seems to be to add a new
access_mode
value - maybecopy
,copy_on_write
, orprivate
.FILE_MAP_COPY
should be passed toMapViewOfFile
on Windows, andPROT_READ
andMAP_PRIVATE
should be passed tommap
on Linux. However, this depends on whether I've overlooked some important subtlety on Linux whenPROT_READ
vsPROT_WRITE
is passed to mmap withMAP_PRIVATE
. If so, perhaps a newmapping_mode
enum withshared
andprivate
values would be desirable.I'm happy to take a stab at this myself if you can give me your thoughts on what the interface for this should be.
The text was updated successfully, but these errors were encountered: