Boost logo

Boost-Commit :

From: technews_at_[hidden]
Date: 2007-12-30 15:24:23


Author: turkanis
Date: 2007-12-30 15:24:23 EST (Sun, 30 Dec 2007)
New Revision: 42379
URL: http://svn.boost.org/trac/boost/changeset/42379

Log:
reimplemented create_large_file() on windows: replaced the painfully slow alternation of writing a char with WriteFile and seeking 1 GB with SetFilePointerEx with an implementation using mapped files that is lightning fast on my development machine. I hate to create a dependence between the file_descriptor tests and the mapped_file tests, but previous implementation sometimes took several minutes to initialize the large file at 9 character offsets
Text files modified:
   branches/iostreams_dev/libs/iostreams/test/large_file_test.cpp | 43 ++++++++++++++-------------------------
   1 files changed, 16 insertions(+), 27 deletions(-)

Modified: branches/iostreams_dev/libs/iostreams/test/large_file_test.cpp
==============================================================================
--- branches/iostreams_dev/libs/iostreams/test/large_file_test.cpp (original)
+++ branches/iostreams_dev/libs/iostreams/test/large_file_test.cpp 2007-12-30 15:24:23 EST (Sun, 30 Dec 2007)
@@ -21,6 +21,7 @@
 #include <boost/iostreams/detail/execute.hpp>
 #include <boost/iostreams/detail/ios.hpp>
 #include <boost/iostreams/device/file_descriptor.hpp>
+#include <boost/iostreams/device/mapped_file.hpp>
 #include <boost/iostreams/positioning.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/test/test_tools.hpp>
@@ -150,7 +151,7 @@
     // Fetch last mod date of this file
     string timestamp =
         "$Date$";
- if (timestamp.size() != 53) { // Length of SVN auto-generated SVN timestamp
+ if (timestamp.size() != 53) { // Length of auto-generated SVN timestamp
         remove_large_file();
         return false;
     }
@@ -190,10 +191,8 @@
             GENERIC_WRITE,
             0,
             NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL |
- FILE_FLAG_RANDOM_ACCESS |
- FILE_FLAG_WRITE_THROUGH,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
             NULL
         );
     if (!hnd)
@@ -217,35 +216,25 @@
         return false;
     }
 
+ // Close handle; all further access is via mapped_file
+ CloseHandle(hnd);
+
     // Initialize file data
     for (int z = 0; z <= 8; ++z) {
-
- // Seek
- length.HighPart = 0;
- length.LowPart = 0;
- length.QuadPart = z * gigabyte;
- LARGE_INTEGER ptr;
- if ( !SetFilePointerEx(hnd, length, &ptr, FILE_BEGIN) ||
- ptr.QuadPart != z * gigabyte )
- {
- CloseHandle(hnd);
- remove_large_file();
- return false;
- }
-
- // Write a character
- char buf[1] = { z + 1 };
- DWORD result;
- BOOL success = WriteFile(hnd, buf, 1, &result, NULL);
- if (!success || result != 1) {
- CloseHandle(hnd);
- remove_large_file();
+ try {
+ mapped_file_params params;
+ params.path = file_name;
+ params.offset = z * gigabyte;
+ params.length = 1;
+ params.mode = BOOST_IOS::out;
+ mapped_file file(params);
+ file.begin()[0] = z + 1;
+ } catch (...) {
             return false;
         }
     }
 
     // Close file
- CloseHandle(hnd);
         return true;
 
 #else // #ifdef BOOST_IOSTREAMS_WINDOWS


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