Encapsulation of file operations by the Mysql database

Source: Internet
Author: User

In viewing Mysql file operations, it operates on files on different operating systems, in addition to using standard C Runtime library functions, including open, close, seek, etc, the file and directory operation functions under Win32 use CreatFile, CloseHandl, and SetFilePointer. Many people may not understand why file operations need to encapsulate two functions.
In fact, there is no difference between using APIs and standard library functions to generate text files and binary files. The same read () corresponds to ReadFile, the same write () corresponds to WriteFile, the same seek () corresponds to SetFilePointer, and the same close corresponds to CloseHandle. Both functions can be used. However, Windows 32 expands the file concept. Whether it is a file, communication device, named pipe, mail slot, disk, or console, it is opened or created using the CreateFile API function. The declaration of this function is:
HANDLE CreateFile (
Lptstr lpFileName, // file name
DWORD dwDesiredAccess, // Access Mode
DWORD dw1_mode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // usually NULL
DWORD dwCreationDistribution, // Creation Method
DWORD dwFlagsAndAttributes, // file attributes and flag
HANDLE hTemplateFile // temporary file HANDLE, usually NULL
If the call is successful, the function returns the file handle. If the call fails, the function returns:
INVALID_HANDLE_VALUE
When ReadFile and WriteFile are used to read and write data, they can be executed simultaneously or asynchronously. Whether the ReadFile and WriteFile functions perform asynchronous operations is determined by the CreateFile function. If the FILE_FLAG_OVERLAPPED flag is specified when CreateFile is called to create a handle, the read and write operations that call ReadFile and WriteFile on the handle are asynchronous. If no asynchronous flag is specified, the read/write operations are synchronized. During synchronous execution, the function is not returned until the operation is complete. This means that the thread will be blocked during synchronous execution, resulting in lower efficiency. During asynchronous execution, the called function will return immediately even if the operation is not completed. Time-consuming I/O operations are performed in the background so that threads can do other things. This greatly improves the efficiency. This is worth learning and learning. For file operations, we can encapsulate the win32 system to improve the efficiency of file operations.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.