Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rather than "always write to the oldest" you can use the "safe file write" technique of:</p> <p>(Assuming you want to end up saving data to <code>foo.data</code>, and a file with that name contains the previous valid version.)</p> <ul> <li>Write new data to <code>foo.data.new</code></li> <li>Rename <code>foo.data</code> to <code>foo.data.old</code></li> <li>Rename <code>foo.data.new</code> to <code>foo.data</code></li> <li>Delete <code>foo.data.old</code></li> </ul> <p>At any one time you've <em>always</em> got at least one valid file, and you can tell which is the one to read just from the filename. This is assuming your file system treats rename and delete operations atomically, of course.</p> <ul> <li>If <code>foo.data</code> and <code>foo.data.new</code> exist, load <code>foo.data</code>; <code>foo.data.new</code> may be broken (e.g. power off during write)</li> <li>If <code>foo.data.old</code> and <code>foo.data.new</code> exist, both should be valid, but something died very shortly afterwards - you <em>may</em> want to load the <code>foo.data.old</code> version anyway</li> <li>If <code>foo.data</code> and <code>foo.data.old</code> exist, then <code>foo.data</code> should be fine, but again something went wrong, or possibly the file couldn't be deleted.</li> </ul> <p>Alternatively, simply <em>always</em> write to a new file, including some sort of monotonically increasing counter - that way you'll never lose any data due to bad writes. The best approach depends on what you're writing though.</p> <p>You could also use <a href="https://msdn.microsoft.com/en-us/library/system.io.file.replace" rel="nofollow"><code>File.Replace</code></a> for this, which basically performs the last three steps for you. (Pass in <code>null</code> for the backup name if you don't want to keep a backup.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload