A method for implementing a memory file system and related devices

By creating memory file engine constructor classes and memory hash tables in QT programming, the problem of QT programming being unable to operate memory files is solved, and the memory file reading and writing operations are realized, meeting the need for QML to display memory pictures.

CN115344546BActive Publication Date: 2025-07-25AFIRSTSOFT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211073695.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-02
Publication Date
2025-07-25
Estimated Expiration
2042-09-02

AI Technical Summary

Technical Problem

Existing QT programming techniques are unable to create and manipulate memory files.

Method used

By creating a memory file engine constructor class, the abstract file system constructor interface is implemented, the memory file engine is registered, and the memory hash table is used to create a memory file. When the path contains a preset prefix, the memory hash table is used to create a memory file. The memory file engine object is created when the path contains a preset prefix, and the memory hash table is queryed for operations.

Benefits of technology

It realizes the creation and operation of memory files in memory, fills the technical gap in QT programming that cannot operate memory files, and meets the need for QML to display memory image files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115344546B_ABST
    Figure CN115344546B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for implementing a memory file system and related devices. The method includes: creating a memory file engine constructor class, implementing the creation of an abstract file system constructor interface, and completing the registration of the memory file engine; creating a memory file through the memory file creation interface of the memory file engine; when a user calls an operation file interface to operate on the memory file, identifying the path of the memory file, and when the path of the memory file contains a preset prefix, creating a memory file engine object and returning it to the QT framework; passing the path of the memory file into the memory file engine object and saving the path of the memory file; querying whether the file name of the file exists in the memory hash table according to the path of the memory file, if not, no processing is performed; if it exists, calling the memory file engine object for operation. The present invention realizes operations such as reading and writing files by creating files in memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of file systems, and in particular, to a method for implementing an in-memory file system and related devices. Background Art

[0002] Existing QT programming techniques can only create, read, and write hard disk files. For example, to display an image, read and write a configuration file, etc., hard disk paths are required, but in-memory files cannot be created, read, or written. Summary of the Invention

[0003] The present invention provides a method for implementing an in-memory file system and related devices, aiming to solve the problem that existing QT programming techniques cannot create, read, or write in-memory files.

[0004] In a first aspect, an embodiment of the present invention provides a method for implementing an in-memory file system, including:

[0005] Create a memory file engine constructor class, implement the creation of an abstract file system constructor interface, complete the registration of the memory file engine, and create a memory hash table for storing the mapping relationship between path strings and binary objects;

[0006] Create an in-memory file through the in-memory file creation interface of the memory file engine;

[0007] When a user calls an operation file interface to operate on an in-memory file, identify the path of the in-memory file. When the path of the in-memory file contains a preset prefix, create a memory file engine object and return it to the QT framework;

[0008] Pass the path of the in-memory file into the memory file engine object and save the path of the in-memory file;

[0009] Query the memory hash table according to the path of the in-memory file to check if the file name of the file exists. If not, do not process; if it exists, call the memory file engine object to operate.

[0010] In a second aspect, an embodiment of the present invention provides a device for implementing an in-memory file system, including:

[0011] A registration unit for creating a memory file engine constructor class, implementing the creation of an abstract file system constructor interface, completing the registration of the memory file engine, and creating a memory hash table for storing the mapping relationship between path strings and binary objects;

[0012] A creation unit for creating an in-memory file through the in-memory file creation interface of the memory file engine;

[0013] An identification unit, configured to identify the path of the memory file when a user calls an operation file interface to operate on the memory file, and create a memory file engine object and return it to the QT framework when the path of the memory file contains a preset prefix;

[0014] A saving unit, configured to pass the path of the memory file into the memory file engine object and save the path of the memory file;

[0015] A query unit, configured to query whether the file name of the file exists in the memory hash table according to the path of the memory file. If not, no processing is performed; if so, the memory file engine object is called for operation.

[0016] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the method for implementing a memory file system described in the first aspect above is implemented.

[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for implementing a memory file system described in the first aspect above is implemented.

[0018] An embodiment of the present invention provides a method for implementing a memory file system, including: creating a memory file engine constructor class, implementing an interface for creating an abstract file system constructor, completing the registration of the memory file engine, and creating a memory hash table for storing the mapping relationship between a path string and a binary object; creating a memory file through the memory file creation interface of the memory file engine; when a user calls an operation file interface to operate on the memory file, identifying the path of the memory file, and creating a memory file engine object and returning it to the QT framework when the path of the memory file contains a preset prefix; passing the path of the memory file into the memory file engine object and saving the path of the memory file; querying whether the file name of the file exists in the memory hash table according to the path of the memory file. If not, no processing is performed; if so, the memory file engine object is called for operation. This method realizes operations such as reading and writing files by creating files in memory, fills the technical gap that QT programming cannot create and operate memory files, and can very conveniently operate memory files through QT native interfaces, solving and meeting the need to display memory picture files in QML (the interface scripting framework of QT). An embodiment of the present invention also provides a device for implementing a memory file system, a computer-readable storage medium, and a computer device, which have the above beneficial effects and will not be elaborated here. Description of the Drawings

[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the accompanying drawings required for the description of the embodiments. Obviously, the accompanying drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.

[0020] Figure 1 It is a schematic flowchart of a method for implementing an in-memory file system provided by an embodiment of the present invention;

[0021] Figure 2 It is a schematic block diagram of an apparatus for implementing an in-memory file system provided by an embodiment of the present invention. Detailed implementation manners

[0022] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.

[0023] It should be understood that when used in this specification and the appended claims, the terms "comprises" and "comprising" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0024] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in this specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.

[0025] It should be further understood that the term " / and / or" used in this specification of the present invention and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0026] Please refer to Figure 1 , an embodiment of the present invention provides a method for implementing an in-memory file system, including:

[0027] S101: Create a constructor class for the in-memory file engine, implement the interface for creating an abstract file system constructor, complete the registration of the in-memory file engine, and create an in-memory hash table for storing the mapping relationship between path strings and binary objects;

[0028] In one embodiment, a MemoryFileEngineHandler class is created. The MemoryFileEngineHandler class can inherit from QAbstractFileEngineHandler (Abstract File System Constructor) and can implement the QAbstractFileEngine* create(const QString& fileName) const (Create Abstract File System Constructor) interface. Among them, the Create Abstract File System Constructor interface is the key entry for creating memory files.

[0029] Among them, for the convenience of using the memory file system, multiple operation interfaces are created in the memory file engine in the embodiments of the present invention as follows:

[0030] Memory file creation interface: static QString createFile(const QString& fileName, const QByteArray& data); Memory file deletion interface: static bool removeFile(const QString& fileName); Memory file data setting interface: static bool setFileData(const QString& fileName, const QByteArray& data); Interface for getting the size of the memory file: size; Interface for getting the read / write position of the memory file: pos; Memory file object closing interface: close; Data flushing interface: flush; Memory file object opening interface: open(QIODevice::OpenMode openMode); Interface for getting the read / write position of the memory file: seek(qint64 pos); Memory file reading interface: read(char* data, qint64 maxlen); Interface for reading a line of data: readLine(char* data, qint64 maxlen); Memory file writing interface: write(const char* data, qint64 len).

[0031] In this embodiment, the created memory hash table is used as the memory file storage structure, and the memory binary file object can be quickly queried through the memory hash table.

[0032] S102: Create a memory file through the memory file creation interface of the memory file engine;

[0033] Specifically, first obtain the incoming file name, and then determine whether the string prefix of the file name contains a preset prefix;

[0034] If the string prefix of the file name contains a preset prefix, query whether the file name exists in the in-memory hash table. If the file name exists, clear the in-memory file corresponding to the file name and set the binary object size of the in-memory file to 0. If the file name does not exist, insert the binary object, establish a mapping relationship from the path string to the binary object, store it in the in-memory hash table, clear the binary object, and set the binary object size of the in-memory file to 0.

[0035] If the string prefix of the file name does not contain the preset prefix, add the preset prefix to the file name, create a mapping relationship from the path string to the binary object, and store the mapping relationship in the in-memory hash table.

[0036] Among them, the in-memory file creation interface can be MemoryFileEngine::createFile.

[0037] S103: When the user calls the operation file interface to operate on the in-memory file, identify the path of the in-memory file. When the path of the in-memory file contains the preset prefix, create an in-memory file engine object and return it to the QT framework;

[0038] In this step, the in-memory file engine object (MemoryFileEngine) inherits from the abstract file system engine (QAbstractFileEngine). Among them, the latest QT version privatizes the abstract file system engine and the abstract file system constructor. The in-memory file engine object cannot directly inherit from the abstract file system engine and needs to copy the relevant header files from the QT source code into the project for use.

[0039] Among them, the in-memory file engine object and the in-memory file engine have the same function. Creating the in-memory file engine object is to implement the corresponding in-memory file engine function when relevant operations need to be performed.

[0040] S104: Pass the path of the in-memory file into the in-memory file engine object and save the path of the in-memory file.

[0041] S105: Query whether the file name of the file exists in the in-memory hash table according to the path of the in-memory file. If it does not exist, do not process it. If it exists, call the in-memory file engine object to perform the operation.

[0042] In this step, when relevant operations are required, the memory file can be accessed through a preset prefix (the preset prefix can be "MemoryFile: / "). In a specific application scenario, a memory file named 123.png is created. Then, the memory file 123.png can be opened by calling the operation interface QFile(MemoryFile: / 123.png), and the memory file 123.png can be operated on. It should be noted that in QML, the memory file needs to be used with file:MemoryFile: / 123.png.

[0043] After accessing the memory file, it is necessary to query whether the file name exists in the memory hash table according to the path of the memory file. If it does not exist, no processing is performed; if it exists, the memory file engine object is called for operation. Calling the memory file engine object for operation mainly involves performing relevant operations by calling the operation interfaces of the memory file engine. Among them, the operation interfaces all need to operate on binary objects.

[0044] Among them, the implementation principle of the memory file reading interface is to query the memory hash table through the path of the memory file and obtain the corresponding binary object, compare the size of the binary object with the maximum length maxlen parameter value, calculate the start position of reading the binary object according to the comparison result, copy the corresponding memory file data to the memory block pointed to by the data pointer through the memory copy function memcpy, and return the number of bytes of the copied memory file data.

[0045] Among them, the implementation principle of the memory file writing interface is to query the binary object through the path of the memory file, append the memory block data to the end of the binary object, and return the number of bytes of the appended memory block data.

[0046] Among them, the implementation principle of the memory file deletion interface is to find the corresponding item in the memory hash table through the memory file deletion interface of the memory file engine object and delete the data of the corresponding item.

[0047] Among them, the implementation principle of the memory file data setting interface is to find the corresponding item in the memory hash table through the memory file data setting interface of the memory file engine object and assign the new data to the associated binary object.

[0048] In the embodiment of the present invention, by creating a memory file in the memory, QT programming can perform operations such as reading, writing, and deleting on the memory file just like operating a hard disk file. For example, a picture file is created in the memory, and then QML can display the picture through the "path" of the picture file. By calling the QFile operation interface, operations such as reading, writing, and deleting can be directly performed on the memory file.

[0049] Please refer to Figure 2, an embodiment of the present invention further provides a device 200 for implementing a memory file system, including:

[0050] A registration unit 201, configured to create a memory file engine constructor class, implement the creation of an abstract file system constructor interface, complete the registration of the memory file engine, and create a memory hash table for storing the mapping relationship between path strings and binary objects;

[0051] A creation unit 202, configured to create a memory file through the memory file creation interface of the memory file engine;

[0052] An identification unit 203, configured to identify the path of the memory file when the user calls an operation file interface to operate on the memory file, and create a memory file engine object and return it to the QT framework when the path of the memory file contains a preset prefix;

[0053] A saving unit 204, configured to pass the path of the memory file into the memory file engine object and save the path of the memory file;

[0054] A query unit 205, configured to query whether the file name of the file exists in the memory hash table according to the path of the memory file. If it does not exist, no processing is performed; if it exists, the memory file engine object is called for operation.

[0055] Further, the registration unit 201 includes:

[0056] An interface creation subunit, configured to create a memory file deletion interface, a memory file creation interface, and a memory file data setting interface.

[0057] Further, the creation unit 202 includes:

[0058] An acquisition subunit, configured to acquire the incoming file name;

[0059] A judgment subunit, configured to judge whether the string prefix of the file name contains a preset prefix;

[0060] A memory file setting subunit, configured to, if the string prefix of the file name contains a preset prefix, query whether the file name exists in the memory hash table. If the file name exists, clear the memory file corresponding to the file name and set the binary object size of the memory file to 0; if the file name does not exist, insert the binary object, establish a mapping relationship from the path string to the binary object and store it in the memory hash table, clear the binary object, and set the binary object size of the memory file to 0.

[0061] Further, the creation unit 202 further includes:

[0062] A memory hash table storage subunit, which is configured to add the preset prefix to the file name if the string prefix of the file name does not contain the preset prefix, create a mapping relationship from a path string to a binary object, and store the mapping relationship in the memory hash table.

[0063] Furthermore, the query unit 205 includes:

[0064] A reading subunit, which is configured to query the memory hash table through the path of the memory file and obtain the corresponding binary object, compare the size of the binary object with the maximum length parameter value, calculate the start position of reading the binary object according to the comparison result, copy the corresponding memory file data to the memory block pointed to by the data pointer through a memory copy function, and return the number of bytes of the copied memory file data.

[0065] Furthermore, the query unit 205 includes:

[0066] A writing subunit, which is configured to query a binary object through the path of the memory file, append the memory block data to the tail of the binary object, and return the number of bytes of the appended memory block data.

[0067] Furthermore, the query unit 205 includes:

[0068] A deletion interface creation subunit, which is configured to find the corresponding item in the memory hash table through the memory file deletion interface of the memory file engine object and delete the data of the corresponding item;

[0069] A data setting interface creation subunit, which is configured to find the corresponding item in the memory hash table through the memory file data setting interface of the memory file engine object and assign new data to the associated binary object.

[0070] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working processes of the above-mentioned devices and units can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.

[0071] The present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed, the method provided in the foregoing embodiments can be implemented. The storage medium may include: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc that can store program codes.

[0072] The present invention also provides a computer device, which may include a memory and a processor. A computer program is stored in the memory. When the processor calls the computer program in the memory, the method provided in the above embodiments can be implemented. Of course, the computer device may further include various network interfaces, power supplies and other components.

[0073] The various embodiments in the specification are described in a progressive manner. The key point of each embodiment is to illustrate the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the device disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple. For the relevant parts, reference can be made to the description in the method part. It should be noted that for those of ordinary skill in the art in the technical field of the present invention, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.

[0074] It should also be noted that in this specification, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of another identical element in the process, method, article or device including the said element.

Claims

1. A method for implementing a memory file system, characterized in that Including: Create a memory file engine constructor class, implement the interface for creating an abstract file system constructor, complete the registration of the memory file engine, and create a memory hash table for storing the mapping relationship between path strings and binary objects; Create a memory file through the memory file creation interface of the memory file engine; When the user calls the operation file interface to operate on the memory file, identify the path of the memory file. When the path of the memory file contains a preset prefix, create a memory file engine object and return it to the QT framework; Pass the path of the memory file into the memory file engine object and save the path of the memory file; Query the memory hash table according to the path of the memory file to check if the file name exists. If it does not exist, no processing is performed; If it exists, call the memory file engine object for operation.

2. The method for implementing an in-memory file system according to claim 1, wherein The memory file engine includes: Create a memory file deletion interface, a memory file creation interface, and a memory file data setting interface.

3. The method for implementing an in-memory file system according to claim 1, wherein The creating of a memory file through the memory file creation interface of the memory file engine includes: Obtain the incoming file name; Judge whether the string prefix of the file name contains a preset prefix; If the string prefix of the file name contains a preset prefix, query the memory hash table to check if the file name exists. If the file name exists, clear the memory file corresponding to the file name and set the binary object size of the memory file to 0; if the file name does not exist, insert the binary object, establish a mapping relationship from the path string to the binary object and store it in the memory hash table, clear the binary object, and set the binary object size of the memory file to 0.

4. The method for implementing an in-memory file system according to claim 3, wherein The creating of a memory file through the memory file creation interface of the memory file engine further includes: If the string prefix of the file name does not contain a preset prefix, add the preset prefix to the file name, create a mapping relationship from the path string to the binary object, and store the mapping relationship in the memory hash table.

5. The method for implementing an in-memory file system according to claim 1, wherein The calling of the memory file engine object for operation includes: Query the memory hash table through the path of the memory file and obtain the corresponding binary object, compare the size of the binary object with the maximum length parameter value, calculate the start position for reading the binary object according to the comparison result, copy the corresponding memory file data to the memory block pointed to by the data pointer through the memory copy function, and return the number of bytes of the copied memory file data.

6. The method for implementing an in-memory file system according to claim 1, wherein The calling of the memory file engine object for operation includes: Query the binary object through the path of the memory file, append the memory block data to the end of the binary object, and return the number of bytes of the appended memory block data.

7. The method for implementing a memory file system according to claim 2, wherein The calling of the memory file engine object for operation includes: Find the corresponding item in the memory hash table through the memory file deletion interface of the memory file engine object and delete the data of the corresponding item; Find the corresponding item in the memory hash table through the memory file data setting interface of the memory file engine object and assign new data to the associated binary object.

8. An apparatus for implementing a memory file system, characterized in that, Including: A registration unit, which is used to create a memory file engine constructor class, implement the creation of an abstract file system constructor interface, complete the registration of the memory file engine, and create a memory hash table for storing the mapping relationship between path strings and binary objects; A creation unit, which is used to create a memory file through the memory file creation interface of the memory file engine; An identification unit, which is used to identify the path of the memory file when the user calls the operation file interface to operate on the memory file, and create a memory file engine object and return it to the QT framework when the path of the memory file contains a preset prefix; A saving unit, which is used to pass the path of the memory file into the memory file engine object and save the path of the memory file; A query unit, which is used to query whether the file name of the file exists in the memory hash table according to the path of the memory file. If it does not exist, no processing is performed; If it exists, call the memory file engine object to perform an operation.

9. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method for implementing a memory file system according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to execute the method for implementing a memory file system according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Qt program memory using static test method for air traffic control training system

    CN104461890A

  • Hash-based mount point lookup in virtual file systems

    US20170228390A1