Article ID: 148505 - Last Review: July 1, 2004 - Revision: 2.1 How To Force Files to Be Flushed to DiskThis article was previously published under Q148505 On This PageSUMMARY
C and C++ file operations, by default, perform their own data caching. This
caching is in addition to the disk caching done by the operating system.
Under certain conditions it may be necessary to ensure your data is fully
flushed to the disk. This article explains how to ensure that your data is
properly flushed to the disk.
MORE INFORMATION
To flush the C runtime buffers, you need a call to fflush for files that
are opened with fopen or a call to the flush function for C++ ofstream
objects. Flushing the operating system's disk cache is a little more
difficult; it depends on the operating system in use.
16-bit Operating Systems - MS-DOS or Windows 3.1In MS-DOS or Windows 3.1 running Smartdrv.exe version 4.0 or later, you have two choices. You can use the _commit C runtime function or link with Commode.obj and use the fflush C runtime function.32-bit Windows Operating SystemsIn 32-bit versions of Windows, the operating system has built-in disk caching. The only way to force a file to be flushed to disk is by linking to Commode.obj.Commode.obj is designed to affect the way the C Runtime handles files. When you link to this .obj file, a call to the C runtime function fflush also forces the operating system to flush its cache to disk, making the call to _commit unnecessary. Sample CodeREFERENCES
See the documentation for fflush(), _commit(), _fileno(), and ofstream.
APPLIES TO
| Article Translations
|

Back to the top
