Use New Flags to Speed Up C Run-time Low-Level I/O Functions

This article was previously published under Q131324
This article has been archived. It is offered "as is" and will no longer be updated.
The low-level file open functions in the C Run-time library for the 32-bitEdition of Visual C++ accept some additional flags to allow you to takeadvantage of Win32-specific file system features. These flags are notavailable in the 16-bit version of Visual C++.

The low-level file open functions are: _open, _wopen, _sopen, and _wsopen.The new flags (and others) can be combined together with the bitwise ORoperator and passed as the 'oflag' argument to the file open functions.

The file open functions call the Win32 function 'CreateFile' to actuallyopen the file with the specified options. The following table relates thesenew C Run-time flags to the equivalent flags that are passed to CreateFile.
You can use these flags to improve file I/O performance in some cases. Forexample, if you need to read from a large file sequentially, and do notneed to jump to different parts of the file, you most likely will improvethe performance of your application by using the _O_SEQUENTIAL flag whenopening the file. This translates to the FILE_FLAG_SEQUENTIAL_SCAN flag forCreateFile.

For more information, please refer to the following sources:

Microsoft Knowledge Base: Read these articles
98756Increased Performance Using FILE_FLAG_SEQUENTIAL_SCAN
103237Using Temporary File Can Improve Application Performance
Visual C++ Books Online: Read the descriptions of the _open/_wopen and
   _sopen/_wsopen functions.  Search on "_open" and "_sopen."				
Visual C++ Run-Time Library Reference, Part 2, Run-Time Reference: Readthe descriptions of _open/_wopen and _sopen/_wsopen.

Win32 Programmer's Reference, Volume 3, Function Reference: Read thedescription of WIN32 API CreateFile.
kbinf 1.00 2.00 2.10 4.00 open sopen option speed up faster

Article ID: 131324 - Last Review: 01/09/2015 05:18:19 - Revision: 2.0

  • The C Run-Time (CRT)
  • kbnosurvey kbarchive kbcrt KB131324