Data storage method, reading method, device, electronic device and storage medium

By adding an identifier to the initial address of the system pointer and performing a partial conversion, the memory waste problem when the data to be stored is smaller than the system pointer is solved, and more efficient memory space utilization is achieved.

CN112015425BActive Publication Date: 2025-03-21CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010825764.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-17
Publication Date
2025-03-21
Estimated Expiration
2040-08-17

AI Technical Summary

Technical Problem

When the data size of the data to be stored is smaller than the system pointer size, the existing pointer-based storage method will cause waste of memory space.

Method used

By adding a preset identifier at the preset position of the system pointer for the corresponding initial address, and performing a calculating conversion of the data to be stored based on the system pointer for the corresponding calculating, the converted data is added to any position in the initial address except the preset identifier, and a pointer to be stored carrying the data to be stored is obtained, and memory space is allocated for it.

Benefits of technology

Without affecting the existing code rules, the data to be stored is taken into account when the size of the data to be stored is smaller than the system pointer, which greatly reduces the waste of memory space and increases the utilization rate of memory space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112015425B_ABST
    Figure CN112015425B_ABST
Patent Text Reader

Abstract

The embodiments of the present invention relate to data storage, and disclose a data storage method, a reading method, a device, an electronic device, and a storage medium. In the present invention, when the size of the stored data is smaller than the size of the system pointer, a preset mark is added to the preset position of the initial address corresponding to the system pointer, thereby identifying the current pointer as a pointer storing the data to be stored; the data to be stored is converted into a base based on the base corresponding to the system pointer, and the converted data to be stored is added to any position except the position of the preset mark in the initial address corresponding to the system pointer, thereby obtaining a pointer to be stored carrying the data to be stored, and finally only a memory space needs to be allocated to the pointer to be stored carrying the data to be stored, and the pointer to be stored is stored in the allocated content space, so that the pointer and the data to be stored can be stored at the same time, thereby greatly reducing the waste of memory space and improving the utilization rate of memory space.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to data storage, and more particularly to a data storage method, a reading method, a device, a equipment and a storage medium. Background Art

[0002] In modern computer systems, object-oriented programming languages ​​generally have the concept of "pointer", which represents the address of data in memory. At present, for the storage of data to be stored, it is usually necessary to apply for two memory spaces, one for storing the data to be stored, and the other for storing the address of the memory space where the data to be stored is located, that is, storing the pointer corresponding to the data to be stored.

[0003] Although the current pointer-based storage method has great advantages, such as being able to quickly locate data to be stored, when the size of the data to be stored is smaller than the size of the pointer, the existence of the pointer will cause a waste of memory space. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to provide a data storage method, a reading method, a device, an electronic device and a storage medium, aiming to solve the above-mentioned technical problems.

[0005] In order to solve the above technical problems, an embodiment of the present invention provides a data storage method, comprising the following steps:

[0006] Get the data to be stored;

[0007] Determine whether the data size of the data to be stored is smaller than the size of the system pointer;

[0008] If it is less than, adding a preset mark at the preset position of the initial address corresponding to the system pointer;

[0009] Based on the base corresponding to the system pointer, the data to be stored is converted into a base, and the converted data to be stored is added to any position of the initial address except the preset mark to obtain a pointer to be stored;

[0010] Allocate memory space for the pointer to be stored, and store the pointer to be stored in the memory space.

[0011] An embodiment of the present invention further provides a data storage device, comprising:

[0012] A data acquisition module, used to acquire data to be stored;

[0013] A size determination module, used for determining whether the data size of the data to be stored is smaller than the size of the system pointer;

[0014] an identification adding module, used for adding a preset identification at a preset position of an initial address corresponding to the system pointer when the size of the data to be stored is smaller than the size of the system pointer;

[0015] A first base conversion module, configured to convert the base of the data to be stored based on the base corresponding to the system pointer;

[0016] A data adding module, used for adding the converted data to be stored to any position in the initial address except the preset mark, to obtain a pointer to be stored;

[0017] The storage module is used to allocate memory space for the pointer to be stored and store the pointer to be stored in the memory space.

[0018] An embodiment of the present invention further provides a data reading method, comprising the following steps:

[0019] Read the pointer value from the memory space;

[0020] Determine whether the value of the pointer carries a preset identifier;

[0021] If yes, determining the data type of the data stored in the memory space based on the preset identifier and the preset data type determination rule;

[0022] Based on the data type, selecting an encoding standard;

[0023] The value of the pointer is converted into base 1 according to the encoding standard to obtain the data stored in the memory space.

[0024] An embodiment of the present invention further provides a data reading device, comprising:

[0025] Pointer reading module, used to read the pointer value from the memory space;

[0026] An identification judgment module, used to judge whether the value of the pointer carries a preset identification;

[0027] a type determination module, configured to determine the data type of the data stored in the memory space based on the preset identifier and a preset data type determination rule when the value of the pointer carries the preset identifier;

[0028] A coding standard selection module, used for selecting a coding standard based on the data type;

[0029] The second binary conversion module is used to convert the value of the pointer into a binary system according to the encoding standard to obtain the data stored in the memory space.

[0030] An embodiment of the present invention further provides an electronic device, including:

[0031] at least one processor; and,

[0032] a memory communicatively connected to the at least one processor; wherein,

[0033] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the data storage method described above, or the data reading method described above.

[0034] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the computer program implements the data storage method or the data reading method as described above.

[0035] Compared with the prior art, the embodiments of the present invention are as follows: when storing data whose size is smaller than the size of the system pointer, a preset mark is added to the preset position of the initial address corresponding to the system pointer, thereby identifying the current pointer as the pointer storing the data to be stored; the data to be stored is converted into a base based on the base corresponding to the system pointer, and the converted data to be stored is added to any position except the preset mark in the initial address corresponding to the system pointer, thereby obtaining the pointer to be stored carrying the data to be stored, and finally, only a memory space needs to be allocated for the pointer to be stored carrying the data to be stored, and the pointer to be stored is stored in the allocated content space, thereby completing the simultaneous storage of the pointer and the data to be stored. Based on this data storage method, without affecting the existing code rules, the situation where the size of the data to be stored is smaller than the system pointer is taken into account, thereby greatly reducing the waste of memory space and improving the utilization rate of memory space.

[0036] In addition, before converting the base system of the data to be stored based on the base system corresponding to the system pointer, the method further includes:

[0037] Determine the data type of the data to be stored;

[0038] The converting the base system of the data to be stored based on the base system corresponding to the system pointer includes:

[0039] Based on the data type, selecting an encoding standard;

[0040] Based on the base corresponding to the system pointer, the data to be stored is converted into a base according to the encoding standard.

[0041] In addition, allocating memory space for the pointer to be stored and storing the pointer to be stored in the memory space includes:

[0042] The pointer to be stored is subjected to binary conversion, and the converted binary data is stored in the memory space in sequence.

[0043] In addition, after performing binary conversion on the pointer to be stored and storing the converted binary data in sequence in the memory space, the method further includes:

[0044] Detecting whether there is any free space in the memory space;

[0045] If yes, fill the empty position with all 0s.

[0046] In addition, after determining whether the data size of the data to be stored is smaller than the size of the system pointer, the method further includes:

[0047] If not less than, corresponding memory spaces are allocated to the system pointer and the data to be stored respectively;

[0048] storing the data to be stored in the memory space corresponding to the data to be stored;

[0049] Obtaining the address of the memory space corresponding to the data to be stored, and assigning the address to the system pointer;

[0050] The assigned system pointer is stored in the memory space corresponding to the system pointer. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0052] Figure 1 is a specific flow chart of the data storage method according to the first embodiment of the present invention;

[0053] Figure 2 is a specific flow chart of a data storage method according to a second embodiment of the present invention;

[0054] Figure 3 is a schematic diagram of the structure of a data storage device according to a third embodiment of the present invention;

[0055] Figure 4 is a specific flow chart of a data storage method according to a fourth embodiment of the present invention;

[0056] Figure 5 is a schematic diagram of the structure of a data storage device according to a fifth embodiment of the present invention;

[0057] Figure 6 is a schematic structural diagram of an electronic device according to a sixth embodiment of the present invention. DETAILED DESCRIPTION

[0058] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be described in detail below with reference to the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present invention, many technical details are provided to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented.

[0059] The division of the following embodiments is for the convenience of description and shall not constitute any limitation on the specific implementation of the present invention. The various embodiments may be combined and referenced with each other without contradiction.

[0060] The first embodiment of the present invention relates to a data storage method. When storing data to be stored whose size is smaller than the size of a system pointer, a preset identifier is added to a preset position of the initial address corresponding to the system pointer, thereby identifying the current pointer as a pointer storing the data to be stored; the data to be stored is converted based on the base corresponding to the system pointer, and the converted data to be stored is added to any position except the preset identifier in the initial address corresponding to the system pointer, thereby obtaining a pointer to be stored carrying the data to be stored, and finally, only a memory space needs to be allocated for the pointer to be stored carrying the data to be stored, and the pointer to be stored is stored in the allocated content space, thereby completing the simultaneous storage of the pointer and the data to be stored. Based on this data storage method, without affecting the existing code rules, the situation where the size of the data to be stored is smaller than the system pointer is taken into account, thereby greatly reducing the waste of memory space and improving the utilization rate of memory space.

[0061] The implementation details of the data storage method of the first embodiment are described below. The following content is only provided for the convenience of understanding and is not necessary for implementing this solution.

[0062] The data storage method provided in the first embodiment is specifically applied to any terminal device capable of executing the method, such as a personal computer, a tablet computer, a smart phone, etc., which are not listed one by one here, and this embodiment does not limit this.

[0063] The specific process of the first implementation method is as follows Figure 1 As shown, the specific steps include:

[0064] Step 101, obtaining data to be stored.

[0065] Specifically, in actual applications, the data to be stored may be data input by a user received at the current moment, or data obtained from a specified website, or data generated by certain applications, which are not listed here one by one.

[0066] Step 102: determine whether the size of the data to be stored is smaller than the size of the system pointer.

[0067] Specifically, if it is determined through judgment that the data size of the data to be stored is smaller than the size specified by the system, step 103 is executed; otherwise, step 106 is executed.

[0068] In addition, it is worth mentioning that in actual applications, the data to be stored mentioned above can be obtained through a received data write request, that is, the received data write request carries the data to be stored. Therefore, the data size of the data to be stored used for judging is specifically applied to the scheduling device in the data storage system of the terminal device to detect the arriving IO operation, and when it is determined that the IO operation is a data write request, the data size of the data to be stored is determined based on the attribute information of the data to be stored carried in the request.

[0069] For easier understanding, the following example is given:

[0070] For example, when the attribute of the data to be stored indicates that the currently acquired data to be stored is an integer int, the data size is determined to be 32 bits.

[0071] For another example, when the attribute of the data to be stored indicates that the currently acquired data to be stored is of character type char, the data size is determined to be 16 bits.

[0072] For another example, when the attribute of the data to be stored indicates that the currently acquired data to be stored is of byte type, the data size is determined to be 8 bits.

[0073] For another example, when the attribute of the data to be stored indicates that the currently acquired data to be stored is a floating point type float, the data size is determined to be 32 bits.

[0074] For another example, when the attribute of the data to be stored indicates that the currently acquired data to be stored is a long integer long, the data size is determined to be 64 bits.

[0075] It can be seen from the above examples that the data size of the data to be stored is specifically determined based on the data type corresponding to the data to be stored.

[0076] The size of the system pointer mentioned above is usually fixed, and its specific size is determined by the number of bits of the operating system.

[0077] For example, for a system pointer of a 64-bit operating system, the pointer size is generally 8 bytes in length, i.e., 64 bits (one byte = 8 bits); for a system pointer of a 32-bit operating system, the pointer size is generally 4 bytes in length, i.e., 32 bits.

[0078] Correspondingly, if the size of the system pointer is 64 bits, the data to be stored that is smaller than the size of the system pointer is specifically the int, char, byte, float listed above, that is, the data size is less than 64 bits; if the size of the system pointer is 32 bits, the data to be stored that is smaller than the size of the system pointer is specifically the char and byte listed above.

[0079] It should be understood that the above is only an example and does not constitute any limitation on the technical solution of this embodiment. In actual applications, those skilled in the art can determine the size of the system pointer according to the operating system, and then filter out the data to be stored whose size is smaller than the system pointer size. This embodiment does not impose any limitation on this.

[0080] Step 103: Add a preset mark at a preset position of the initial address corresponding to the system pointer.

[0081] Specifically, in this implementation, the initial address corresponding to the system pointer is represented by all 0s.

[0082] Since one hexadecimal digit represents a 4-bit binary number, for a 64-bit system pointer, the corresponding initial address is 16 bits (16*4=64), specifically "0x0000000000000000".

[0083] Correspondingly, for a 32-bit system pointer, the corresponding initial address is 8 bits (8*4=32), specifically represented as "0x00000000".

[0084] In addition, the preset identifier mentioned above is specifically "1" in this embodiment, and the preset position mentioned above is specifically the first position from the right of the initial address. Based on this rule, after the preset identifier "1" is added to the first position from the right of the initial address corresponding to the 64-bit system pointer, the initial address corresponding to the system pointer becomes "0x00000000000000001".

[0085] It should be understood that the preset logo and the specified preset position given above are all specific implementation methods and do not constitute any limitation to the specific technical scheme of this embodiment. In practical applications, technical personnel in this field can select appropriate content as the preset logo as needed, and specify the appropriate position as the preset position where the preset logo needs to be added.

[0086] Step 104 , based on the base corresponding to the system pointer, perform base conversion on the data to be stored, and add the converted data to be stored to any position in the initial address except the preset mark to obtain a pointer to be stored.

[0087] Specifically, since the system pointer is usually in hexadecimal, the above conversion is specifically to convert the data to be stored into hexadecimal, thereby obtaining the data to be stored represented in hexadecimal.

[0088] It should be understood that since a preset identifier has been added to the preset position in the initial address corresponding to the system pointer, when the hexadecimal data to be stored is added to the initial address corresponding to the system pointer, in order to avoid adding data at the preset position, which results in the preset identifier being replaced, the converted hexadecimal data to be stored needs to be added to any position in the initial address except the preset identifier.

[0089] Accordingly, in order to facilitate the subsequent reading of correct data from the pointer to be stored carrying data, it is necessary to pre-agreed on a rule that the converted data to be stored is added to any position in the initial address except the preset mark.

[0090] To facilitate subsequent storage and reading, in this embodiment, a preset identifier is added to the first bit from the right of the initial address, and the converted data to be stored is added in reverse order to the second bit from the right of the initial address, and the positions after the second bit.

[0091] Furthermore, in actual applications, different data types of data to be stored may be converted into hexadecimal format according to different encoding standards. Therefore, in order to quickly and accurately convert the base of the data to be stored, it is necessary to first determine the data type of the data to be stored before converting the base of the data to be stored based on the base corresponding to the system pointer.

[0092] It should be noted that the data types mentioned here are not the eight data types commonly used in computer systems (byte, short, int, long, float, double, boolean, char), but indicate whether the current data to be stored is Chinese characters, English, numbers, characters, etc.

[0093] The determination of the data type of the data to be stored can be specifically determined according to the attributes of the data to be stored, which will not be elaborated here.

[0094] Accordingly, after determining the data type of the data to be stored, the operation of performing radix conversion on the data to be stored based on the radix corresponding to the system pointer is specifically implemented in the following two steps:

[0095] First, select an encoding standard based on the data type.

[0096] Then, perform radix conversion on the data to be stored according to the encoding standard based on the radix corresponding to the system pointer.

[0097] Regarding the above-mentioned encoding standards, in the prior art, they are generally divided into Western language encoding standards (such as ASCII), Chinese character encoding standards (such as GB2312, GBK, GB18030), and global character encoding standards (such as ISO / IEC 10646 and Unicode).

[0098] Furthermore, in order to quickly and accurately select an encoding standard according to the determined data type, in practical applications, a corresponding relationship between various data types and the above-mentioned encoding standards can be established in advance.

[0099] For example, map the Chinese character format to any of the above-mentioned Chinese character encoding standards, map numbers and English to the Western language encoding standard, and map characters to any of the above-mentioned global character encoding standards.

[0100] For the sake of easy understanding, the following is illustrated with examples:

[0101] Suppose the data to be stored is the Chinese character "啊". Then determine its data type as Chinese character. Based on the preset mapping relation table, determine that the encoding standard to be selected is the Chinese character encoding standard.

[0102] Suppose the selected Chinese character encoding standard is GB2312. When performing hexadecimal conversion on the data to be stored "啊" according to GB2312, by traversing each area in GB2312, it is determined that the character "啊" is located at the 01st position in the 16th area. Therefore, the data to be stored after the final conversion is specifically represented as "1601".

[0103] Accordingly, when adding the content obtained from the above conversion to the initial address corresponding to the system pointer (64 bits), starting from the second digit from the right, add them in reverse order one by one. The final pointer to be stored is "0x0000000000016011".

[0104] It should be understood that the above is only an example for illustration and does not constitute a specific limitation on the technical solution of this embodiment.

[0105] Step 105, allocate memory space for the pointer to be stored and store the pointer to be stored in the memory space.

[0106] It should be understood that, since in actual applications, the data stored in the computer are all stored in binary format, i.e. "0" or "1", when allocating memory space for the pointer to be stored and storing the pointer to be stored in the allocated memory space, it is necessary to first perform binary conversion on the pointer to be stored, and then store the converted binary data in sequence in the memory space.

[0107] In addition, the memory space allocated for the pointer to be stored is specifically determined based on the number of bits of the pointer to be stored.

[0108] For example, if the system pointer is 64 bits, the pointer to be stored is still 64 bits, and the allocated memory space is 64 bits.

[0109] Correspondingly, when the system pointer is 32 bits, the pointer to be stored is 32 bits, and the allocated memory space is 32 bits.

[0110] In addition, it is worth mentioning that, since the size of the memory space allocated for the pointer to be stored in this embodiment is specifically determined according to the maximum length supported by the pointer to be stored, there may still be free space after the binary data is stored in the memory space. In order to ensure that the data subsequently read from the memory space is the data stored at the current moment, after the pointer to be stored is binary-converted and the converted binary data is sequentially stored in the memory space, it is possible to further detect whether there is still free space in the memory space.

[0111] Correspondingly, if there are free positions in the memory space, the free positions are filled with all 0s, so that the entire memory space can be filled and the data subsequently read out can be guaranteed to be the stored data.

[0112] Step 106, respectively allocating corresponding memory spaces for the system pointer and the data to be stored.

[0113] Step 107: store the data to be stored in the memory space corresponding to the data to be stored.

[0114] Step 108, obtaining the address of the memory space corresponding to the data to be stored, and assigning the address to the system pointer.

[0115] Step 109, storing the assigned system pointer into the memory space corresponding to the system pointer.

[0116] It can be known from the description of the above steps 106 to 109 that when the data size of the data to be stored is larger than the size of the system pointer, that is, when a 64-bit or 32-bit system pointer cannot store the data to be stored, a memory space needs to be allocated separately for the data to be stored. And in order to facilitate the subsequent data reading, the memory space can be quickly located, and then the stored data is read out therefrom, the address of the memory space specifically used to store the data to be stored needs to be assigned to the system pointer, that is, the initial address of the system pointer is updated to the address of the memory space used to store the data to be stored, and then the updated system pointer is stored in the storage space specifically used to store the system pointer.

[0117] Therefore, the data storage method provided by the present embodiment, when obtaining the data to be stored, by judging whether the data size of the data to be stored is smaller than the size of the system pointer, when it is determined that the data to be stored is smaller than the size of the system pointer, by adding a preset mark at the preset position of the initial address corresponding to the system pointer, thereby identifying the current pointer as a pointer storing the data to be stored, that is, not the existing pointer that simply indicates the address of the memory space corresponding to the data to be stored. Then, by converting the data to be stored based on the base corresponding to the system pointer, and adding the converted data to be stored to any position except the position of the preset mark in the initial address corresponding to the system pointer, thereby obtaining the pointer to be stored carrying the data to be stored, and finally only needing to allocate a memory space for the pointer to be stored carrying the data to be stored, and storing the pointer to be stored in the allocated content space, the pointer and the data to be stored can be stored simultaneously. Based on this data storage method, without affecting the existing code rules, the situation that the size of the data to be stored is smaller than the system pointer is taken into account, thereby greatly reducing the waste of memory space and improving the utilization rate of memory space.

[0118] The second embodiment of the present invention relates to a data storage method. The second embodiment takes the case where the data to be stored is an integer constant as an example, and specifically describes the data storage method given in the first embodiment.

[0119] For ease of explanation, this implementation takes the example of storing a 4-byte integer constant "123" in a 64-bit computer system.

[0120] First, in a 64-bit computer system, the initial address corresponding to the system pointer is "0x0000000000000000".

[0121] Next, since the data "123" to be stored is an int constant with a length of 4 bytes, that is, it requires a maximum of 32 bits of space, it can be judged that the data "123" to be stored is smaller than the size of the system pointer, so it can be added to the system pointer, that is, only one memory space is allocated to store the pointer and data.

[0122] Next, when it is determined that the data size of the data to be stored is smaller than the size of the system pointer, a preset flag "1" is added to the first position from the right of the initial address "0x0000000000000000" to obtain "0x0000000000000001".

[0123] Next, convert "123" from decimal to hexadecimal to obtain "7b", and add the obtained "7b" to the second digit from the right of "0x0000000000000001" and the position after the second digit in reverse order to obtain "0x00000000000007b1".

[0124] Next, a 64-bit memory space is allocated for the pointer to be stored "0x00000000000007b1", and each digit after the "0x" part of the pointer to be stored is converted into binary.

[0125] It should be understood that a hexadecimal "0" is still 0 after binary conversion, but one hexadecimal 0 is represented by four 0s. Therefore, this embodiment mainly describes the conversion of the "7b1" part.

[0126] Specifically, after binary conversion of "1", the data obtained is "0001"; after binary conversion of "b", the data obtained is "1011"; after binary conversion of "7", the data obtained is "0111".

[0127] Finally, the binary numbers obtained above are stored in the memory space allocated for them in reverse order, that is, according to Figure 2 The format is used for storage, and the free positions are directly filled with all 0s.

[0128] Thus, based on the data storage method provided by the present invention, the storage of the integer constant "123" is completed.

[0129] In addition, it should be understood that the step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs that do not change the core design of the algorithm and process are all within the scope of protection of this patent.

[0130] A third embodiment of the present invention relates to a data storage device, such as Figure 3 As shown, it includes: a data acquisition module 301, a size judgment module 302, an identification adding module 303, a first base conversion module 304, a data adding module 305 and a storage module 306.

[0131] Among them, the data acquisition module 301 is used to acquire the data to be stored; the size judgment module 302 is used to judge whether the data size of the data to be stored is smaller than the size of the system pointer; the identifier adding module 303 is used to add a preset identifier at a preset position of the initial address corresponding to the system pointer when the size of the data to be stored is smaller than the size of the system pointer; the first base conversion module 304 is used to perform base conversion on the data to be stored based on the base corresponding to the system pointer; the data adding module 305 is used to add the converted data to be stored to any position in the initial address except the preset identifier to obtain the pointer to be stored; the storage module 306 is used to allocate memory space for the pointer to be stored, and store the pointer to be stored in the memory space.

[0132] Furthermore, in another example, the data storage device further includes a data type determination module.

[0133] Specifically, the data type determination module is used to determine the data type of the data to be stored.

[0134] Correspondingly, the first base conversion module 304 is specifically used to select a coding standard based on the data type; and perform base conversion on the data to be stored according to the coding standard based on the base corresponding to the system pointer.

[0135] In addition, in another example, the storage module 306 is specifically used to perform binary conversion on the pointer to be stored, and store the converted binary data in the memory space in sequence.

[0136] In addition, in another example, the storage module 306 is further used to detect whether there are any free positions in the memory space; if so, the free positions are filled with all zeros.

[0137] In addition, in another example, the storage module 306 is also used to allocate corresponding memory space to the system pointer and the data to be stored respectively; store the data to be stored in the memory space corresponding to the data to be stored; obtain the address of the memory space corresponding to the data to be stored, and assign the address to the system pointer; store the assigned system pointer in the memory space corresponding to the system pointer.

[0138] It is not difficult to find that this embodiment is a device embodiment corresponding to the first or second embodiment, and this embodiment can be implemented in conjunction with the first or second embodiment. The relevant technical details mentioned in the first or second embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the first or second embodiment.

[0139] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.

[0140] A fourth embodiment of the present invention relates to a data reading method, which cooperates with the data storage method provided in the first or second embodiment.

[0141] The implementation details of the data storage method of the fourth embodiment are described below. The following content is only provided for the convenience of understanding and is not necessary for implementing this solution.

[0142] The data reading method provided in the fourth embodiment is specifically applied to any terminal device that can execute the method, such as a personal computer, a tablet computer, a smart phone, etc., which are not listed one by one here, and this embodiment does not limit this.

[0143] The specific process of the fourth implementation mode is as follows Figure 4 As shown, the specific steps include:

[0144] Step 401, read the value of the pointer from the memory space.

[0145] Step 402: determine whether the value of the pointer carries a preset identifier.

[0146] Step 403: Determine the data type of the data stored in the memory space based on the preset identifier and the preset data type determination rule.

[0147] Step 404: Select an encoding standard based on the data type.

[0148] Step 405: perform base conversion on the value of the pointer according to the encoding standard to obtain data stored in the memory space.

[0149] For the sake of convenience, this embodiment combines Figure 2 Provide explanation.

[0150] When reading the value of the pointer from the memory space, the computer system automatically reads the value of the pointer stored in the current memory space bit by bit (64 bits in total). Since when storing the pointer to be stored with the preset identifier, the preset identifier in the pointer to be stored will be represented by 4 bits in the memory space, when the preset identifier is added to the first bit from the right corresponding to the initial position of the system pointer, the 4 bits corresponding to the memory space should be Figure 2 0th to 3rd place.

[0151] Assume that the rightmost bit of the system pointer is 0, which means that the system pointer is a pointer to the existing corresponding data address; if the rightmost bit is an arbitrary preset identifier, it indicates that the system pointer is a pointer carrying data to be stored. Based on this rule, we can know that as long as Figure 2 If 1 appears in bits 0 to 3, it means that the current pointer is a pointer that carries data, that is, it is not a pointer to the address of the memory space corresponding to the existing storage data.

[0152] Next, according to the specific Figure 2 The data at the 1st, 2nd and 3rd bits in the READ_MODE_READ_DATA determine the data type of the data to be read.

[0153] Assume that the preset data type determination rule stipulates that when the preset identifier is "1", "000" is specified to represent an integer type; when the preset identifier is "2", since the binary data obtained after binary conversion of 2 is "0010", "001" is specified to be a character type; when the preset identifier is "3", since the binary data obtained after binary conversion of 3 is "0101", "010" is specified to be a byte type.

[0154] Accordingly, based on the above preset data type determination rule, it can be known that "000" indicates that the data type to be read is an integer, that is, Figure 2 The data stored in the given memory space is an integer constant.

[0155] Next, based on the determined data type, a suitable encoding standard is selected from the agreed encoding standards. Since the data to be read is an integer constant, that is, a number, the selected encoding standard may be ASCII.

[0156] Finally, the value of the pointer is converted into base 1 according to the encoding standard to obtain the data stored in the memory space.

[0157] Specifically, the remaining 60 bits are read out in sequence, and every 4 bits are converted into a hexadecimal data. The value of the pointer taken out is "0x00000000000007b". Then, the taken value is converted into the decimal number corresponding to the integer constant, and the data obtained is "123", that is, Figure 2The data read out from the given memory space is the integer constant "123", which is the same as the data stored in the second implementation mode, that is, the current reading operation is correct.

[0158] Step 406: locate the memory space where the data to be read is located according to the value of the pointer.

[0159] Step 407, reading the data from the located memory space.

[0160] It is not difficult to find from the above description that the data reading method provided in this embodiment, when it is necessary to read the data stored based on the pointer from the memory space, reads the value of the pointer from the memory space storing the pointer, and then determines whether the value of the read pointer carries a preset identifier, thereby determining whether the current pointer is a pointer carrying data or a pointer that simply represents the address of the memory space where the data is stored. When it is determined that the current pointer is a pointer carrying data, the data type of the data stored in the current memory space is determined based on the preset identifier and the preset data type determination rule, and then the appropriate encoding standard is selected according to the determined data type, and the value of the pointer is converted according to the selected encoding standard, and then the data stored in the memory space is read out; when it is determined that the current pointer is a pointer that simply represents the address of the memory space where the data is stored, the memory space where the data to be read is located is located according to the value of the current pointer, and then the stored data is read from the located memory space. Based on this data reading method, without affecting the existing code rules, by adding a simple judgment logic, it is possible to take into account the existing reading of data from the memory space storing data separately, and to take into account the reading of data from the memory space carrying the pointer of the data, without affecting the system performance, greatly improving the data reading efficiency.

[0161] A fifth embodiment of the present invention relates to a data reading device, such as Figure 5 As shown, it includes: a pointer reading module 501, an identification judgment module 502, a type determination module 503, a coding standard selection module 504 and a binary conversion module 505.

[0162] Among them, the pointer reading module 501 is used to read the value of the pointer from the memory space; the identifier judgment module 502 is used to judge whether the value of the pointer carries a preset identifier; the type determination module 503 is used to determine the data type of the data stored in the memory space based on the preset identifier and the preset data type determination rule when the value of the pointer carries the preset identifier; the encoding standard selection module 504 is used to select the encoding standard based on the data type; the binary conversion module 505 is used to convert the value of the pointer according to the encoding standard to obtain the data stored in the memory space.

[0163] Furthermore, in another example, the data reading device further includes a positioning module and a data reading module.

[0164] Specifically, the positioning module is used to locate the memory space where the data to be read is located according to the value of the pointer; and the data reading module is used to read the data from the located memory space.

[0165] It is not difficult to find that this embodiment is a device embodiment corresponding to the fourth embodiment, and this embodiment can be implemented in conjunction with the fourth embodiment. The relevant technical details mentioned in the fourth embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the fourth embodiment.

[0166] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.

[0167] A sixth embodiment of the present invention relates to an electronic device, such as Figure 6 As shown, it includes at least one processor 601; and a memory 602 that is communicatively connected to the at least one processor 601; wherein the memory 602 stores instructions that can be executed by the at least one processor 601, and the instructions are executed by the at least one processor 601 so that the at least one processor 601 can execute the data storage method or data reading method described in the above method implementation.

[0168] The memory 602 and the processor 601 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus links various circuits of one or more processors 601 and the memory 602 together. The bus can also link various other circuits such as peripheral devices, voltage regulators, and power management circuits together, which are all well known in the art, and therefore, are not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor is transmitted on a wireless medium through an antenna, and further, the antenna also receives data and transmits the data to the processor.

[0169] The processor 601 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 602 can be used to store data used by the processor 601 when performing operations.

[0170] The seventh embodiment of the present application relates to a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the data storage method or data reading method described in the above method embodiment.

[0171] Those skilled in the art can understand that all or part of the steps in the above-mentioned implementation method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each implementation of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0172] Those skilled in the art will appreciate that the above-mentioned embodiments are specific embodiments for implementing the present invention, and in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present invention.

Claims

1. A data storage method, characterized in that: include: Get the data to be stored; Determine whether the data size of the data to be stored is smaller than the size of the system pointer; If it is less than, adding a preset mark at the preset position of the initial address corresponding to the system pointer; Based on the base corresponding to the system pointer, the data to be stored is converted into a base, and the converted data to be stored is added to any position of the initial address except the preset mark to obtain a pointer to be stored; Allocating memory space for the pointer to be stored, and storing the pointer to be stored in the memory space; Before converting the data to be stored based on the system corresponding to the system pointer, the method further includes: determining the data type of the data to be stored; wherein, converting the data to be stored based on the system corresponding to the system pointer includes: selecting a coding standard based on the data type; converting the data to be stored based on the system corresponding to the system pointer according to the coding standard; The data size of the data to be stored is specifically determined based on the data type corresponding to the data to be stored; The preset identifier is used to identify the current pointer as a pointer storing the data to be stored.

2. The data storage method according to claim 1, characterized in that: The allocating memory space for the pointer to be stored, and storing the pointer to be stored in the memory space, comprises: The pointer to be stored is subjected to binary conversion, and the converted binary data is stored in the memory space in sequence.

3. The data storage method according to claim 2, characterized in that: After performing binary conversion on the pointer to be stored and storing the converted binary data in sequence in the memory space, the method further includes: Detecting whether there is any free space in the memory space; If yes, fill the empty position with all 0s.

4. The data storage method according to claim 1, characterized in that: After determining whether the data size of the data to be stored is smaller than the size of the system pointer, the method further includes: If not less than, corresponding memory spaces are allocated to the system pointer and the data to be stored respectively; storing the data to be stored in the memory space corresponding to the data to be stored; Obtaining the address of the memory space corresponding to the data to be stored, and assigning the address to the system pointer; The assigned system pointer is stored in the memory space corresponding to the system pointer.

5. A data storage device, characterized in that: include: A data acquisition module, used to acquire data to be stored; A size determination module, used for determining whether the data size of the data to be stored is smaller than the size of the system pointer, wherein the data size of the data to be stored is specifically determined based on the data type corresponding to the data to be stored; an identification adding module, used for adding a preset identification at a preset position of an initial address corresponding to the system pointer when the size of the data to be stored is smaller than the size of the system pointer, wherein the preset identification is used to identify the current pointer as a pointer storing the data to be stored; A first base conversion module is configured to perform base conversion on the data to be stored based on the base corresponding to the system pointer, wherein before the base conversion on the data to be stored based on the base corresponding to the system pointer, it further includes: determining the data type of the data to be stored; wherein the base conversion on the data to be stored based on the base corresponding to the system pointer includes: selecting a coding standard based on the data type; and performing base conversion on the data to be stored according to the coding standard based on the base corresponding to the system pointer; A data adding module, used for adding the converted data to be stored to any position in the initial address except the preset mark, to obtain a pointer to be stored; The storage module is used to allocate memory space for the pointer to be stored and store the pointer to be stored in the memory space.

6. A data reading method, used for reading data stored in the data storage method according to any one of claims 1 to 4, characterized in that: include: Read the pointer value from the memory space; Determine whether the value of the pointer carries a preset identifier, wherein the preset identifier is a pointer that identifies the current pointer as a pointer storing data to be stored; If yes, then based on the preset identifier and the preset data type determination rule, determine the data type of the data stored in the memory space, the data type indicating whether the current data to be stored is Chinese characters, English, numbers or characters; Based on the data type, selecting a coding standard, the coding standard including: a Western coding standard, a Chinese character coding standard, and a global character coding standard; The value of the pointer is converted into base 1 according to the encoding standard to obtain the data stored in the memory space.

7. A data reading device, used to execute the data reading method according to claim 6, characterized in that: Pointer reading module, used to read the pointer value from the memory space; An identification judgment module, used to judge whether the value of the pointer carries a preset identification; a type determination module, configured to determine the data type of the data stored in the memory space based on the preset identifier and a preset data type determination rule when the value of the pointer carries the preset identifier; A coding standard selection module, used for selecting a coding standard based on the data type; The second binary conversion module is used to convert the value of the pointer into a binary system according to the encoding standard to obtain the data stored in the memory space.

8. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data storage method according to any one of claims 1 to 4, or the data reading method according to claim 6.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data storage method according to any one of claims 1 to 4 or the data reading method according to claim 6 is implemented.

Citation Information

Patent Citations

  • Creation method and access method for universal memory entity

    CN105955727A

  • Method and device for executing critical zone operation

    CN107239415A