Write file without system cache and hdd

How can I write something to a file in C ++ without using the system cache and disk cache? I just want to write exactly on hdd, regardless of all the system cache settings.

+3
source share
3 answers

If you are not writing a disk device driver, you cannot guarantee that there will be no cache or processing with your record.

The C time library provides fflush(FILE *)for this. Windows has FlushFileBuffers, as well as a flag that you can pass in CreateFile( FILE_FLAG_NO_BUFFERING) (which itself adds restrictions on what you can do).

, . . , , , .

, (. ReplaceFile Transactional NTFS Windows).

+3

. Windows FILE_FLAG_NO_BUFFERING, CreateFile, . .

+2

On Linux, you can pass O_DIRECTin open(2)to try to avoid the OS cache, but you do not have the same level of control over the disk cache.

+1
source

Source: https://habr.com/ru/post/1731906/


All Articles