On 9/18/2016 8:17 AM, Andrei Alexandrescu via Digitalmars-d wrote:
There is actually an even better way at the application level. Consider
a function in std.file:

updateS, Range)(S name, Range data);

updateFile does something interesting: it opens the file "name" for
reading AND writing, then reads data from the Range _and_ the file. For
as long as the data and the contents in the file agree, it just moves
reading along. At the first difference between the data and the file
contents, starts writing the data into the file through the end of the
range.

So this makes zero writes (and leaves the "last modified time" intact)
if the file has the same content as the data. Better yet, if it so
happens that the file and the data have the same prefix, there's less
writing going on, which IIRC is faster for most filesystems. Saving on
writes happens to be particularly nice on new solid-state drives.

Who wants to take this with testing, measurements etc? It's a cool mini
project.


Andrei

This is nice in the case of no changes, but problematic in the case of some changes. The standard write new, rename technique never has either file in a half-right state. The file is atomically either old or new and nothing in between. This can be critical.

Reply via email to