mysql| encapsulates MySQL's encapsulation of file operations
In view of the MySQL file operation, it found that the operation of the file on different operating systems, in addition to the use of standard C Run-time library functions, including open, close, seek, and so on, the file and directory operation functions under Win32 using Creatfile, Closehandl, SetFilePointer and so on, do not understand why the operation of the file to encapsulate two sets of functions.
See the relevant information, in fact, the use of APIs and standard library functions can generate text files and binaries, there is no difference in this regard. 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 declaration of the function is:
HANDLE CreateFile (
LPCTSTR lpFileName,//filename
DWORD dwdesiredaccess,//access mode
DWORD dwShareMode,//Shared mode
Lpsecurity_attributes lpsecurityattributes,//usually NULL
DWORD dwcreationdistribution,//How to create
DWORD dwflagsandattributes,//file properties and Flags
HANDLE htemplatefile//Temp file handle, usually null
);
If the call succeeds, the function returns the handle to the file, and if the call fails, the function returns INVALID_HANDLE_VALUE.
When read and write with ReadFile and WriteFile, it can be performed synchronously or asynchronously. 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 a decrease in efficiency. 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service