try 4096 alignment.
authorCarl Hetherington <cth@carlh.net>
Thu, 6 Aug 2020 07:26:49 +0000 (09:26 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 6 Aug 2020 07:38:43 +0000 (09:38 +0200)
src/tools/dcpomatic_disk_writer.cc

index 0348557c3c63e58c7b516574c18c2d5112133fc2..97594df31918cd31685e0ec60e79f62e22657d7e 100644 (file)
@@ -78,6 +78,7 @@ DCPOMATIC_ENABLE_WARNINGS
 #include <boost/foreach.hpp>
 #include <iostream>
 
+using std::bad_alloc;
 using std::cin;
 using std::min;
 using std::string;
@@ -125,7 +126,10 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
                throw CopyError (String::compose("Failed to open file %1", from.string()), 0);
        }
 
-       uint8_t* buffer = new uint8_t[block_size];
+       uint8_t* buffer = aligned_alloc (4096, block_size);
+       if (!buffer) {
+               throw bad_alloc();
+       }
        Digester digester;
 
        int progress_frequency = 5000;
@@ -138,7 +142,7 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
                if (read != this_time) {
                        fclose (in);
                        ext4_fclose (&out);
-                       delete[] buffer;
+                       free (buffer);
                        throw CopyError (String::compose("Short read; expected %1 but read %2", this_time, read), 0);
                }
 
@@ -149,13 +153,13 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
                if (r != EOK) {
                        fclose (in);
                        ext4_fclose (&out);
-                       delete[] buffer;
+                       free (buffer);
                        throw CopyError ("Write failed", r);
                }
                if (written != this_time) {
                        fclose (in);
                        ext4_fclose (&out);
-                       delete[] buffer;
+                       free (buffer);
                        throw CopyError (String::compose("Short write; expected %1 but wrote %2", this_time, written), 0);
                }
                remaining -= this_time;
@@ -169,7 +173,7 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
 
        fclose (in);
        ext4_fclose (&out);
-       delete[] buffer;
+       free (buffer);
 
        return digester.get ();
 }