Commit-To-Disk 常量Commit-To-Disk Constants

Microsoft 专用Microsoft Specific


#include <stdio.h>  


这些特定于 Microsoft 的常量指定将与打开的文件关联的缓冲区刷新到操作系统缓冲区还是磁盘。These Microsoft-specific constants specify whether the buffer associated with the open file is flushed to operating system buffers or to disk. 模式包含在指定读/写访问权限的类型(“r”、“w”、“a”、“r+”、“w+”、“a+”)的字符串中。The mode is included in the string specifying the type of read/write access ("r", "w", "a", "r+", "w+", "a+").

提交到磁盘模式如下所示:The commit-to-disk modes are as follows:

将指定缓冲区的未写入内容写入磁盘。Writes the unwritten contents of the specified buffer to disk. 此提交到磁盘功能仅在显式调用 fflush_flushall 函数时生效。This commit-to-disk functionality only occurs at explicit calls to either the fflush or the _flushall function. 此模式在处理敏感数据时很有用。This mode is useful when dealing with sensitive data. 例如,如果在调用 fflush_flushall 后程序终止,您可以确保数据已到达操作系统的缓冲区。For example, if your program terminates after a call to fflush or _flushall, you can be sure that your data reached the operating system's buffers. 但是,除非文件是使用 c 选项打开的,否则当操作系统也终止时,数据可能从不会将文件传送到磁盘。However, unless a file is opened with the c option, the data might never make it to disk if the operating system also terminates.

将指定缓冲区的未写入内容写入操作系统的缓冲区。Writes the unwritten contents of the specified buffer to the operating system's buffers. 操作系统可以缓存数据然后确定写入到磁盘的最佳时间。The operating system can cache data and then determine an optimal time to write to disk. 在大多数情况下,此行为有助于产生有效的程序行为。Under many conditions, this behavior makes for efficient program behavior. 但是,如果保留数据很重要(如银行交易或机票信息)请考虑使用 c 选项。However, if the retention of data is critical (such as bank transactions or airline ticket information) consider using the c option. n 模式是默认设置。The n mode is the default.


c 和 n 选项不是 fopen 的 ANSI 标准的一部分,而是 Microsoft 扩展,因此不应在需要 ANSI 可移植性的情况下使用。The c and n options are not part of the ANSI standard for fopen, but are Microsoft extensions and should not be used where ANSI portability is desired.

将提交到磁盘功能用于现有代码Using the Commit-to-Disk Feature with Existing Code

默认情况下,调用 fflush_flushall 库函数会将数据写入操作系统维护的缓冲区。By default, calls to the fflush or _flushall library functions write data to buffers maintained by the operating system. 操作系统确定将数据实际写入磁盘的最佳时间。The operating system determines the optimal time to actually write the data to disk. 利用运行库的提交到磁盘功能,您可以确保关键数据直接写入磁盘而不是操作系统的缓冲区。The commit-to-disk feature of the run-time library lets you ensure that critical data is written directly to disk rather than to the operating system's buffers. 您可以将此功能提供给现有程序,而无需通过将该程序的对象文件与 COMMODE.OBJ 链接来重写程序。You can give this capability to an existing program without rewriting it by linking its object files with COMMODE.OBJ.

在生成的可执行文件中,调用 fflush 会将缓冲区的内容直接写入磁盘,而调用 _flushall 会将所有缓冲区的内容写入磁盘。In the resulting executable file, calls to fflush write the contents of the buffer directly to disk, and calls to _flushall write the contents of all buffers to disk. 这两个函数是唯一受 COMMODE.OBJ 影响函的数。These two functions are the only ones affected by COMMODE.OBJ.

结束 Microsoft 专用END Microsoft Specific

请参阅See Also

流 I/O Stream I/O
_fdopen、_wfdopen _fdopen, _wfdopen
fopen、_wfopen fopen, _wfopen
全局常量Global Constants