The complication of this problem is that there are several "caches" in the game.
C ++ streams have their own internal buffering mechanism. Streams do not ask the OS to write to disk until (a) you send a sufficient amount of data to a buffer, which the stream library considers that the record will not be wasted. (B) you request a flash specifically (c) the stream is in line buffering mode and you sent it via endl . Any data in these buffers is lost when the program crashes.
The OS will buffer recordings to make the best use of the limited number of available IO disks. Records will usually be discarded within five to thirty seconds; if the programmer (or library) calls fdatasync(2) or fsync(2) or sync(2) (which requests to clear all dirty data). Any data in the OS buffers is written to disk (in the end), when the program crashes, it is lost if the kernel crashes.
The hard disk will buffer recordings to try best to use slow head, rotational delay, etc. Data arrives in this buffer when the OS flushes its caches. Data in these buffers is written to disk when the program crashes, they will probably be written to disk if the kernel crashes and can be written to disk if the power is suddenly removed from the disk. (Some have enough power to keep writing their buffers, usually it takes less than a second.)
sarnold
source share