Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73052 - sandbox/mmap/boost/mmap
From: dsaritz_at_[hidden]
Date: 2011-07-13 10:41:23


Author: psiha
Date: 2011-07-13 10:41:21 EDT (Wed, 13 Jul 2011)
New Revision: 73052
URL: http://svn.boost.org/trac/boost/changeset/73052

Log:
Fixed the mapped_view_base<Element>::unmap() member function.
Fixed the map_read_only_file() function.
Added the map_file() utility function.
Text files modified:
   sandbox/mmap/boost/mmap/memory_mapping.cpp | 53 ++++++++++++++++++++++++++++++++++-----
   sandbox/mmap/boost/mmap/memory_mapping.hpp | 8 ++++-
   2 files changed, 52 insertions(+), 9 deletions(-)

Modified: sandbox/mmap/boost/mmap/memory_mapping.cpp
==============================================================================
--- sandbox/mmap/boost/mmap/memory_mapping.cpp (original)
+++ sandbox/mmap/boost/mmap/memory_mapping.cpp 2011-07-13 10:41:21 EDT (Wed, 13 Jul 2011)
@@ -379,7 +379,46 @@
 }
 
 
-mapped_view<unsigned char const> map_read_only_file( char const * const file_name )
+basic_mapped_view map_file( char const * const file_name, std::size_t const desired_size )
+{
+ guard::native_handle const file_handle
+ (
+ create_file
+ (
+ file_name,
+ file_flags::create
+ (
+ file_flags::handle_access_rights::read | file_flags::handle_access_rights::write,
+ file_flags::share_mode ::read,
+ file_flags::open_policy::open_or_create,
+ file_flags::system_hints ::sequential_access,
+ file_flags::on_construction_rights::read | file_flags::on_construction_rights::write
+ )
+ )
+ );
+
+ set_file_size( file_handle.handle(), desired_size );
+
+ return basic_mapped_view::map
+ (
+ file_handle.handle(),
+ // Implementation note:
+ // Windows APIs interpret zero as 'whole file' but we still need to
+ // query the file size in order to be able properly set the end pointer.
+ // (13.07.2011.) (Domagoj Saric)
+ mapping_flags::create
+ (
+ mapping_flags::handle_access_rights::read | mapping_flags::handle_access_rights::write,
+ mapping_flags::share_mode::shared,
+ mapping_flags::system_hint::uninitialized
+ ),
+ get_file_size( file_handle.handle() ),
+ 0
+ );
+}
+
+
+basic_mapped_read_only_view map_read_only_file( char const * const file_name )
 {
     guard::native_handle const file_handle
     (
@@ -396,14 +435,14 @@
         )
     );
 
- return mapped_view<unsigned char const>::map
+ return basic_mapped_read_only_view::map
     (
         file_handle.handle(),
- #ifdef _WIN32
- 0 // Windows APIs interpret zero as 'whole file'
- #else // POSIX
- get_file_size( file_handle.handle() )
- #endif // OS impl
+ // Implementation note:
+ // Windows APIs interpret zero as 'whole file' but we still need to
+ // query the file size in order to be able properly set the end pointer.
+ // (13.07.2011.) (Domagoj Saric)
+ get_file_size( file_handle.handle() )
     );
 }
 

Modified: sandbox/mmap/boost/mmap/memory_mapping.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/memory_mapping.hpp (original)
+++ sandbox/mmap/boost/mmap/memory_mapping.hpp 2011-07-13 10:41:21 EDT (Wed, 13 Jul 2011)
@@ -164,6 +164,9 @@
 template <typename Element>
 class mapped_view;
 
+typedef mapped_view<unsigned char > basic_mapped_view;
+typedef mapped_view<unsigned char const> basic_mapped_read_only_view;
+
 namespace guard
 {
 //------------------------------------------------------------------------------
@@ -269,7 +272,7 @@
     template <typename Element>
     void mapped_view_base<Element>::unmap( mapped_view_base<Element> const & mapped_range )
     {
- unmap<unsigned char const>( make_basic_view( mapped_range ) );
+ mapped_view_base<unsigned char const>::unmap( make_basic_view( mapped_range ) );
     }
 
     template <>
@@ -417,7 +420,8 @@
 );
 
 
-mapped_view<unsigned char const> map_read_only_file( char const * file_name );
+basic_mapped_view map_file ( char const * file_name, std::size_t desired_size );
+basic_mapped_read_only_view map_read_only_file( char const * file_name );
 
 //------------------------------------------------------------------------------
 } // namespace boost


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk