Subject: [Boost-bugs] [Boost C++ Libraries] #1612: Support for PAGE_WRITECOPY(Windows) and MAP_PRIVATE(POSIX) flags
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-01-31 13:31:59
#1612: Support for PAGE_WRITECOPY(Windows) and MAP_PRIVATE(POSIX) flags
------------------------------+---------------------------------------------
Reporter: Jorge Lodos | Owner: turkanis
Type: Feature Requests | Status: new
Milestone: Boost 1.36.0 | Component: iostreams
Version: Boost 1.34.1 | Severity: Not Applicable
Keywords: |
------------------------------+---------------------------------------------
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!
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1612>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC