Opened 15 years ago
Closed 12 years ago
#1612 closed Feature Requests (fixed)
Support for PAGE_WRITECOPY(Windows) and MAP_PRIVATE(POSIX) flags
Reported by: | Jorge Lodos | Owned by: | Jonathan Turkanis |
---|---|---|---|
Milestone: | Boost 1.36.0 | Component: | iostreams |
Version: | Boost 1.34.1 | Severity: | Not Applicable |
Keywords: | Cc: |
Description
The use of these flags allos for opening the file in read mode and creating the mapping so it could be written to without really changing the underlying physical object. Currently they are infered from the open mode in the OS primitives, defaulting to read only (in) or synchronized read/write (out). An additional flag parameter could be added to the mapped_file_params structure and open methods. Possible portable values for this flags could be PRIVATE and SHARED, defaulting to SHARED which is the current behavior. A bool parameter could be used instead.
Sample implementation:
You might want to pass objects of this class by reference most of the time, now they are being passed by value everywhere struct mapped_file_params {
explicit mapped_file_params()
: mode(), offset(0), length(static_cast<std::size_t>(-1)),
new_file_size(0), hint(0), flags(SHARED)
{ }
explicit mapped_file_params(const std::string& path)
: path(path), mode(), offset(0),
length(static_cast<std::size_t>(-1)), new_file_size(0), hint(0), flags(SHARED)
{ }
std::string path; BOOST_IOS::openmode mode; stream_offset offset; std::size_t length; stream_offset new_file_size; const char* hint; int flags;
};
Modified functions in mapped_file_source (assign flgas in the implementation)
explicit mapped_file_source( const std::string& path,
size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED );
void open( const std::string& path,
size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED );
Modified functions in mapped_file (assign flgas in the implementation)
explicit mapped_file( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
size_type length = max_length, stream_offset offset = 0, int flags = SHARED );
void open( const std::string& path,
BOOST_IOS::openmode mode =
BOOST_IOS::in | BOOST_IOS::out,
size_type length = max_length, stream_offset offset = 0, int flags = SHARED );
Modified functions in mapped_file_sik (assign flgas in the implementation)
explicit mapped_file_sink( const std::string& path,
size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED );
void open( const std::string& path,
size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED);
In mapped_file_source::open_impl(mapped_file_params p) implementation, the lines pimpl_->mapped_handle_ = ::CreateFileMappingA( pimpl_->handle_, NULL, readonly ? PAGE_READONLY : PAGE_READWRITE, 0, 0, NULL ); should be replaced by:
DWORD protect = readonly ? PAGE_READONLY : PAGE_READWRITE; if (p.flags == PRIVATE)
protect = PAGE_WRITECOPY;
pimpl_->mapped_handle_ =
::CreateFileMappingA( pimpl_->handle_, NULL,
protect, 0, 0, NULL );
The lines void* data = ::mmap( hint, pimpl_->size_, readonly ? PROT_READ : (PROT_READ | PROT_WRITE), readonly ? MAP_PRIVATE : MAP_SHARED, pimpl_->handle_, p.offset ); should be replaced by:
void* data = ::mmap( hint, pimpl_->size_,
readonly ? PROT_READ : (PROT_READ | PROT_WRITE), p.flags == PRIVATE ? MAP_PRIVATE : MAP_SHARED, pimpl_->handle_, p.offset );
Thank you!
Attachments (3)
Change History (8)
by , 15 years ago
Attachment: | mapped_file.hpp added |
---|
by , 15 years ago
Attachment: | mapped_file.2.zip added |
---|
Implementation that allows for different flags for the underlying file and the mapping.
comment:1 by , 13 years ago
Was this fixed in [46692]? Also, the boost license information was removed in that change, presumably by mistake. Is it okay to put it back? Thanks.
comment:2 by , 12 years ago
Since Jonathan is listed in more/blanket-permission.txt, I'd just add the Boost license back.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Modified with the bool variant