Boost C++ Libraries: Ticket #1612: Support for PAGE_WRITECOPY(Windows) and MAP_PRIVATE(POSIX) flags https://svn.boost.org/trac10/ticket/1612 <p> 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. </p> <p> Sample implementation: </p> <p> <em> You might want to pass objects of this class by reference most of the time, now </em> they are being passed by value everywhere struct mapped_file_params { </p> <blockquote> <p> explicit mapped_file_params() </p> <blockquote> <p> : mode(), offset(0), length(static_cast&lt;std::size_t&gt;(-1)), </p> <blockquote> <p> new_file_size(0), hint(0), flags(SHARED) </p> </blockquote> <p> { } </p> </blockquote> <p> explicit mapped_file_params(const std::string&amp; path) </p> <blockquote> <p> : path(path), mode(), offset(0), </p> <blockquote> <p> length(static_cast&lt;std::size_t&gt;(-1)), new_file_size(0), hint(0), flags(SHARED) </p> </blockquote> <p> { } </p> </blockquote> <p> std::string path; BOOST_IOS::openmode mode; stream_offset offset; std::size_t length; stream_offset new_file_size; const char* hint; int flags; </p> </blockquote> <p> }; </p> <p> <em> Modified functions in mapped_file_source (assign flgas in the implementation) </em></p> <blockquote> <p> explicit mapped_file_source( const std::string&amp; path, </p> <blockquote> <p> size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED ); </p> </blockquote> </blockquote> <blockquote> <p> void open( const std::string&amp; path, </p> <blockquote> <p> size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED ); </p> </blockquote> </blockquote> <p> <em> Modified functions in mapped_file (assign flgas in the implementation) </em></p> <blockquote> <p> explicit mapped_file( const std::string&amp; path, </p> <blockquote> <p> BOOST_IOS::openmode mode = </p> <blockquote> <p> BOOST_IOS::in | BOOST_IOS::out, </p> </blockquote> <p> size_type length = max_length, stream_offset offset = 0, int flags = SHARED ); </p> </blockquote> <p> void open( const std::string&amp; path, </p> <blockquote> <p> BOOST_IOS::openmode mode = </p> <blockquote> <p> BOOST_IOS::in | BOOST_IOS::out, </p> </blockquote> <p> size_type length = max_length, stream_offset offset = 0, int flags = SHARED ); </p> </blockquote> </blockquote> <p> <em> Modified functions in mapped_file_sik (assign flgas in the implementation) </em></p> <blockquote> <p> explicit mapped_file_sink( const std::string&amp; path, </p> <blockquote> <p> size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED ); </p> </blockquote> <p> void open( const std::string&amp; path, </p> <blockquote> <p> size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED); </p> </blockquote> </blockquote> <p> <em> In mapped_file_source::open_impl(mapped_file_params p) implementation, </em> the lines <em> pimpl_-&gt;mapped_handle_ = </em> ::CreateFileMappingA( pimpl_-&gt;handle_, NULL, <em> readonly ? PAGE_READONLY : PAGE_READWRITE, </em> 0, 0, NULL ); <em> should be replaced by: </em></p> <blockquote> <p> DWORD protect = readonly ? PAGE_READONLY : PAGE_READWRITE; if (p.flags == PRIVATE) </p> <blockquote> <p> protect = PAGE_WRITECOPY; </p> </blockquote> <p> pimpl_-&gt;mapped_handle_ = </p> <blockquote> <blockquote> <p> ::CreateFileMappingA( pimpl_-&gt;handle_, NULL, </p> <blockquote> <p> protect, 0, 0, NULL ); </p> </blockquote> </blockquote> </blockquote> </blockquote> <p> <em> The lines </em> void* data = ::mmap( hint, pimpl_-&gt;size_, <em> readonly ? PROT_READ : (PROT_READ | PROT_WRITE), </em> readonly ? MAP_PRIVATE : MAP_SHARED, <em> pimpl_-&gt;handle_, p.offset ); </em> should be replaced by: </p> <blockquote> <p> void* data = ::mmap( hint, pimpl_-&gt;size_, </p> <blockquote> <p> readonly ? PROT_READ : (PROT_READ | PROT_WRITE), p.flags == PRIVATE ? MAP_PRIVATE : MAP_SHARED, pimpl_-&gt;handle_, p.offset ); </p> </blockquote> </blockquote> <p> Thank you! </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1612 Trac 1.4.3 Jorge Lodos Thu, 31 Jan 2008 17:48:15 GMT attachment set https://svn.boost.org/trac10/ticket/1612 https://svn.boost.org/trac10/ticket/1612 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">mapped_file.hpp</span> </li> </ul> <p> Modified with the bool variant </p> Ticket Jorge Lodos Thu, 31 Jan 2008 17:53:34 GMT attachment set https://svn.boost.org/trac10/ticket/1612 https://svn.boost.org/trac10/ticket/1612 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">mapped_file.zip</span> </li> </ul> <p> Modified with the bool variant </p> Ticket lodos at segurmatica.cu Mon, 03 Mar 2008 14:14:55 GMT attachment set https://svn.boost.org/trac10/ticket/1612 https://svn.boost.org/trac10/ticket/1612 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">mapped_file.2.zip</span> </li> </ul> <p> Implementation that allows for different flags for the underlying file and the mapping. </p> Ticket Daniel James Sat, 02 Jan 2010 12:46:30 GMT <link>https://svn.boost.org/trac10/ticket/1612#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1612#comment:1</guid> <description> <p> Was this fixed in <a class="changeset" href="https://svn.boost.org/trac10/changeset/46692" title="applied changes from Jorge Lodos (with modifications)">[46692]</a>? Also, the boost license information was removed in that change, presumably by mistake. Is it okay to put it back? Thanks. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 17 Jun 2010 01:53:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1612#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1612#comment:2</guid> <description> <p> Since Jonathan is listed in more/blanket-permission.txt, I'd just add the Boost license back. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 17 Jun 2010 03:23:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1612#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1612#comment:3</guid> <description> <p> Hmmm. The functionality is undocumented, even though it exists. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 24 Jun 2010 21:22:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1612#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1612#comment:4</guid> <description> <p> I added documentation in <a class="changeset" href="https://svn.boost.org/trac10/changeset/63298" title="Document private mapping with mapped_file. Refs #1612.">[63298]</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 25 Jun 2010 14:38:12 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1612#comment:5 https://svn.boost.org/trac10/ticket/1612#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket