01-14-2022 06:02 PM
We're using LV 2018, 32 bit.
We're writing to a text file and want to avoid losing data if the system crashes, hence we need to either flush or close the file relatively frequently, to ensure that any data that LabVIEW thinks has been written to the file does indeed get written and not left hanging around in a Windows buffer right before a crash.
If you want to explicitly flush a file, you can use the flush file function. But does anyone know if the Close File function also forces a flush? E.g. when you close a file, are you guaranteed that the Windows buffers will be flushed and the data will be written right then?
01-14-2022 06:43 PM
@Dave_Thomson wrote:
We're using LV 2018, 32 bit.
We're writing to a text file and want to avoid losing data if the system crashes, hence we need to either flush or close the file relatively frequently, to ensure that any data that LabVIEW thinks has been written to the file does indeed get written and not left hanging around in a Windows buffer right before a crash.
If you want to explicitly flush a file, you can use the flush file function. But does anyone know if the Close File function also forces a flush? E.g. when you close a file, are you guaranteed that the Windows buffers will be flushed and the data will be written right then?
I think flushing a file forces a disk write, while closing a file just closes it and leaves it up to the operating system to decide when to write it to disk.
01-15-2022 09:49 AM
I was going to say "Write a LabVIEW program to test your assumption", but then I realized that the problem was embedded in the phrase "right before a crash", and how do you get LabVIEW to "simulate a crash"? [I suppose you could use the not-to-be-used LabVIEW "Abort" function ...
If you are writing your text file "intermittently", say every minute or minutes or so, you can save yourself the worry by doing the following:
The file will be "vulnerable to a crash" only during the time you are updating it, and if a crash does occur during this (brief, I hope) time, you'll probably have the last-but-one version of the file sitting intact on the disk. I'm pretty sure I've used this technique in the past ...
Bob Schor
01-15-2022 11:51 AM
My guess is that it depends if windows write caching is enabled (default?) or disabled.
I would assume that if write caching is enabled, windows will complete the write independent of LabVIEW so you should be OK unless Windows also crashes hard... 😄