Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The encapsulation method of file operation by Mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "Mysql on the file operation of the encapsulation method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Mysql on the file operation of the encapsulation method" it!

In viewing the operation of Mysql on files, it is found that in addition to using standard C runtime functions, including open, close, seek, etc., the file and directory operation functions under Win32 use CreatFile, CloseHandl, SetFilePointer, etc., and do not understand why the operation of files should be encapsulated into two sets of functions.

Looking at the relevant information, in fact, using API and standard library functions can generate text files and binary files, there is no difference at this point. Read () corresponds to ReadFile, write () corresponds to WriteFile, seek () corresponds to SetFilePointer, and close corresponds to CloseHandle. Both sets of functions can be used. But the Win 32 system extends the concept of files. Files, communication devices, named pipes, mail slots, disks, or consoles are all opened or created using the API function CreateFile. The function is declared as follows:

HANDLE CreateFile (

LPCTSTR lpFileName, / / File name

DWORD dwDesiredAccess, / / access mode

DWORD dwShareMode, / / sharing mode

LPSECURITY_ATTRIBUTES lpSecurityAttributes, / / usually NULL

DWORD dwCreationDistribution, / / creation method

DWORD dwFlagsAndAttributes, / / File attributes and flags

Handle to the HANDLE hTemplateFile / / temporary file, 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 reading and writing with ReadFile and WriteFile, it can be executed either synchronously 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 calling the CreateFile create handle, the read and write operations to the handle are asynchronous by calling ReadFile and WriteFile, and synchronous if no asynchronous flag is specified. During synchronous execution, the function does not return until the operation is complete. This means that threads are blocked during synchronous execution, resulting in inefficiency. When executed asynchronously, the called function returns immediately even if the operation has not yet been completed. The time-consuming Imax O operation takes place in the background so that the thread can do something else. This can greatly improve efficiency. This point is worthy of our study and reference. We can also encapsulate the win32 system in the operation of files to improve the efficiency of file operations.

Thank you for your reading, the above is the content of "Mysql encapsulation method for file operation". After the study of this article, I believe you have a deeper understanding of the encapsulation method of Mysql file operation, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report