I have some questions about file storage in Windows programming.
First, when you write to a file, it is not written to the disc directly, is it?
But when you want it to be written to the disc and flush the buffers, how do I do that?
And, if then I close the handle, it is saved to the disc, however, if it happened to crash, will it be saved anyway?
>First, when you write to a file, it is not written to the disc directly
..it depends on flags specified when opening file (via CreateFile()), you can specify flags there to ignore buffering, default is to use it.
>when you want it to be written to the disc and flush the buffers
If you did not turned write buffering off, you can call FlushFileBuffers() to flush buffers for given file.
>if then I close the handle, it is saved to the disc, however, if it happened to crash
If crash happens after succesfull CloseHandle(), data should be written already and OK - closing a handle includes flushing of all relevant buffers as well. Otherwise it depends on settings of buffers and your own requests for flushing, how much of the file will be saved.
Remember, there is also the cache on the disc drive itself, always possible to flush the OS cache to the UDMA controller, but that writes to the cache on the drive, because the cache is so much faster than the physical device. Technically possible that after flushing everything you can possible flush, a badly times power drop could prevent the magnetic media from being completely updated.
It says 23 posts and newbie basically, but you were around before weren't you?
adrianxw: of course :).. i haven't been checking this board for quite a time due to bad internet access but times changed and i'm back.. quite a surprise to me you do remember :)