In view of the MySQL file operation, it operates on different operating systems, in addition to using standard C Run-time library functions, including open, close, seek, and so on, the file and directory operations functions under WIN32 use Creatfile, Closehandl, SetFilePointer and so on, many people may not understand why the operation of the file to encapsulate two sets of functions.
There is no difference between using APIs and standard library functions to generate text files and binary files. The corresponding to the read () is ReadFile, corresponding to the write () is the WriteFile, with the Seek () corresponds to the SetFilePointer, and close corresponds to the CloseHandle. Both sets of functions are available. But the win 32 system extends the concept of the file. Whether it is a file, a communications device, a named pipe, a mail slot, a disk, or a console, it is opened or created using API function CreateFile. The function is declared as:
HANDLE CreateFile (
LPCTSTR lpfilename,//filename
DWORD dwdesiredaccess,//access mode
DWORD dwShareMode ,//Shared mode
Lpsecurity_attributes lpsecurityattributes,//usually null
DWORD dwcreationdistribution,//creation mode
Dwor D dwflagsandattributes,//file properties and flags
HANDLE htemplatefile//temporary file handle, usually null
if the call succeeds, the function returns the handle to the file, and if the call fails, the function returns: br> Invalid_handle_value
can be executed synchronously or asynchronously when read and write with ReadFile and WriteFile. Whether the ReadFile and WriteFile functions are performing asynchronous operations is determined by the CreateFile function. If the FILE_FLAG_OVERLAPPED flag is specified when the handle is invoked on the CreateFile, then the read-write operation of the ReadFile and WriteFile to the handle is asynchronous, and if no asynchronous flag is specified, the read-write operation is synchronized. When executed synchronously, the function does not return until the operation completes. This means that the thread is blocked while the synchronization is executing, resulting in an efficiencyFall. When executed asynchronously, the called function returns immediately, even if the operation is not completed. Time-consuming I/O operations are done in the background so that the thread can do something else. This can greatly improve the efficiency. This is worthy of our learning and reference, for us in the operation of the file can also be Win32 system encapsulation to improve the efficiency of file operations.