开发者

Windows equivalent to sync()

I do most of my programming on embedded processors, or on linux. When i need to sync data to my persistant store, i usually use the sync(2) system call. Is there an equivelent 开发者_运维问答for Windows?


http://msdn.microsoft.com/en-us/library/aa364439(VS.85).aspx http://www.codeproject.com/KB/system/EjectMediaByLetter.aspx

FlushFileBuffers with a handle to a volume. You have to do this for every volume :(


Use FlushFileBuffers, but you need a handle to the file you need flushed.


If you are using posix file functions (fopen() etc.), you can use _flushall:

http://msdn.microsoft.com/en-us/library/s9xk9ehd%28v=vs.80%29.aspx


See here: https://jeffpar.github.io/kbarchive/kb/066/Q66052/

When you initially open your file using fopen, include the "c" mode option as the LAST OPTION:

fopen( path, "wc") // w - write mode, c - allow immediate commit to disk

Then when you want to force a flush to disk, call

_flushall()

We made this call before calling

fclose()

Note that this approach does NOT required Administrative rights, which FlushFileBuffers does require.

From that above site:

"Microsoft C/C++ version 7.0 introduces the "c" mode option for the fopen() function. When an application opens a file and specifies the "c" mode, the run-time library writes the contents of the file buffer to disk when the application calls the fflush() or _flushall() function. "

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜