Information flash memory storage method, device, computer equipment and storage medium
By calculating the remaining storage space of the flash memory block and generating adaptive boot information, the problem of flash memory storage space waste is solved, and the utilization rate of the flash memory storage space and the information storage efficiency are improved.
Patent Information
- Application Number
- CN202210487586.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-06
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-05-06
AI Technical Summary
In the prior art, the problem of low flash memory storage space utilization is mainly due to the waste of fixed-length storage blocks caused by the indefinite length of information to be stored.
By obtaining the storage end address of the target flash memory block and the fixed length of the boot information, the remaining storage space is calculated, and when the length of the information to be stored is less than the remaining space, boot information containing the storage address is generated. The boot information is stored one bit after the starting address of the flash memory block, and the information to be stored is stored to the corresponding address according to the storage address.
This effectively avoids the waste of storage space, improves the utilization rate of the flash memory storage space, ensures that the information to be stored and the boot information are stored in the same target flash memory block, and avoids the boot information remaining after the storage information is erased.
Smart Images

Figure CN114968841B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information storage technology, and in particular to a flash memory storage method, device, computer equipment and storage medium for information. Background Art
[0002] Currently, when storing information in flash memory, the flash memory block is usually divided into multiple storage areas of fixed length. The length of the storage area is generally determined according to the length of the longest application information. The information to be stored is then stored in the divided storage area to facilitate the management of the stored information.
[0003] However, in information storage scenarios, the length of the information to be stored is unknown. Storing information of variable length in a fixed-length storage area will cause shorter information to occupy a longer storage area after being stored, resulting in a waste of flash memory storage space and reducing the utilization rate of flash memory storage space. Therefore, how to improve the utilization rate of flash memory storage space has become an urgent problem to be solved. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a method, apparatus, computer device, and storage medium for storing information in a flash memory to solve the problem of low utilization of flash memory storage space.
[0005] In a first aspect, an embodiment of the present invention provides a method for storing information in a flash memory, the method comprising:
[0006] Obtaining the storage end address of the target flash memory block and the storage length of the flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information;
[0007] obtaining an information length of information to be stored, and generating boot information including a storage address when the information length is less than the remaining storage space, wherein the storage address is a starting address of a target segment storage space in the remaining storage space;
[0008] Storing the boot information in the flash memory block, wherein the boot information storage start address is the next digit after the storage end address;
[0009] According to the storage address, the information to be stored is stored in the corresponding address.
[0010] In a second aspect, an embodiment of the present invention provides a flash memory storage device for information, the flash memory storage device comprising:
[0011] A remaining space calculation module is used to obtain the storage end address of the target flash memory block and the storage length of the flash memory block, and calculate the remaining storage space of the flash memory block in combination with the fixed length of the boot information;
[0012] a boot information generating module, configured to obtain the information length of the information to be stored, and, when the information length is less than the remaining storage space, generate boot information including a storage address, wherein the storage address is a starting address of a target segment storage space in the remaining storage space;
[0013] A boot information storage module, configured to store the boot information in the flash memory block, wherein the boot information storage start address is the next digit after the storage end address;
[0014] The information storage module is used to store the information to be stored in a corresponding address according to the storage address.
[0015] In a third aspect, an embodiment of the present invention provides a computer device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the flash memory storage method as described in the first aspect when executing the computer program.
[0016] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the flash memory storage method as described in the first aspect is implemented.
[0017] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0018] The storage end address and storage length of the target flash memory block are obtained, and the remaining storage space of the flash memory block is calculated in combination with the fixed length of the boot information; the information length of the information to be stored is obtained, and when the information length is less than the remaining storage space, boot information containing the storage address is generated, the storage address is the starting address of the target segment storage space in the remaining storage space, the boot information is stored in the flash memory block, and the starting address of the boot information storage is the last digit of the storage end address; according to the storage address, the information to be stored is stored in the corresponding address, and a target flash memory block with an adapted length is selected according to the information length of the information to be stored, thereby avoiding waste of storage space, and storing the information to be stored and the corresponding boot information in the same target flash memory block, thereby avoiding residual boot information after the storage information is erased, thereby improving the utilization rate of the flash memory storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 1 is a flow chart of a method for storing information in a flash memory provided by the first embodiment of the present invention;
[0021] Figure 2 This is a schematic diagram of the structure of the chain storage method provided in the first embodiment of the present invention;
[0022] Figure 3 This is a schematic diagram of the structure of the reverse order storage method provided in the first embodiment of the present invention;
[0023] Figure 4 This is a flow chart of a flash memory storage method for information provided by Embodiment 2 of the present invention;
[0024] Figure 5 This is a schematic structural diagram of a flash memory storage device for information provided in a third embodiment of the present invention;
[0025] Figure 6 This is a structural diagram of a computer device provided in Example 4 of the present invention. DETAILED DESCRIPTION
[0026] In the following description, specific details such as particular system structures and techniques are provided for purposes of illustration, not limitation, to facilitate a thorough understanding of the embodiments of the present invention. However, it will be apparent to those skilled in the art that the present invention may be practiced in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
[0027] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0028] It will also be understood that the term "and / or" used in the present description and appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0029] As used in the present specification and the appended claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0030] In addition, in the description of the present specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0031] References to "one embodiment" or "some embodiments" in the present specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present invention. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in yet other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0032] It should be understood that the order of execution of the steps in the following embodiments does not necessarily mean the order in which they are executed. The order in which each process is executed should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0033] In order to illustrate the technical solution of the present invention, specific embodiments are provided below.
[0034] See also Figure 1 , is a flow chart of a flash memory storage method for information provided in a first embodiment of the present invention. The above-mentioned flash memory storage method can be applied to a server. The computer device corresponding to the server is connected to a corresponding flash memory (i.e., flash) and can read the storage end address, storage length, etc. of each flash memory block of the flash memory. The server also has a bucket storage constraint function, a data address acquisition function, and an information storage function.
[0035] like Figure 1 As shown, the flash memory storage method may include the following steps:
[0036] Step S101 , obtaining the storage end address of the target flash memory block and the storage length of the flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information.
[0037] The flash memory block may refer to a page (ie, page) of the flash memory, which is the smallest unit of the flash memory. The target flash memory block may refer to a currently selected flash memory block.
[0038] The storage end address may refer to the end address of the corresponding flash memory block when the previous storage was completed. The storage length is the maximum storage length of the corresponding flash memory block. The maximum storage length is predetermined by the flash memory during production and is a fixed value. For example, the maximum storage length may be 1024 bytes, 2048 bytes, etc.
[0039] Boot information may refer to guidance information for providing the storage address of data to be stored. The length of the boot information is pre-set by the implementer and cannot be changed after setting to avoid confusion when subsequently reading the flash memory. For example, the length of the boot information may be set to eight bytes.
[0040] The remaining storage space may refer to the total length of blank bits in the corresponding flash memory block where no data is stored.
[0041] Specifically, the sum of the storage end address of the target flash memory block and the fixed length of the boot information is calculated, and then the sum of the storage end address and the fixed length of the boot information is subtracted from the storage length of the flash memory block to obtain the remaining storage space.
[0042] The above-mentioned steps of obtaining the storage end address of the target flash memory block, the storage length of the flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information obtain the remaining storage space of the target flash memory block, so as to subsequently determine whether to store the information to be stored in the target storage block in combination with the length of the information to be stored, play a role of pre-detection, and can effectively improve storage efficiency.
[0043] Step S102: obtaining the information length of the information to be stored, and generating boot information including the storage address when the information length is less than the remaining storage space.
[0044] The information to be stored may refer to information pushed by the electric meter, information uploaded to a data concentrator unit (DCU), etc. The information to be stored includes the length of the information to be stored and the data of the information to be stored.
[0045] The storage address may refer to a starting address of a target segment storage space in the remaining storage space, and the target segment storage space may refer to a corresponding storage location of the information to be stored in the remaining storage space.
[0046] Specifically, in this embodiment, the length of the information to be stored may refer to the length of the information data to be stored. The length of the information to be stored is usually a fixed byte, for example, it may be 2 bytes in length. The length of the information data to be stored is determined by the actually obtained information data to be stored. The length of the information data to be stored is usually indefinite and is set to n bytes in length.
[0047] In one embodiment, the length of the information to be stored may refer to the total length of the information data to be stored and the length of the information to be stored.
[0048] Optionally, if the message length is greater than or equal to the remaining storage space, then:
[0049] According to the identifier corresponding to the current flash memory block, the flash memory block corresponding to the last digit of the identifier is used as the target flash memory block;
[0050] Return to the step of obtaining the storage end address and storage length of the target flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information, until the identifier corresponding to the current flash memory block is the same as the end identifier of the bucket storage.
[0051] Among them, the identifier can refer to the page identifier corresponding to the flash memory block, which is used to represent the page number of the flash memory block. The end identifier can refer to the maximum page identifier of the bucket storage. The bucket storage can refer to the flash memory circular shift storage mode in units of pages. The identifiers corresponding to the flash memory blocks in the bucket storage include the minimum page identifier and the maximum page identifier.
[0052] Specifically, in this embodiment, the flash memory block can adopt a bucket storage constraint. The bucket storage constraint process can be that if the identifier corresponding to the current flash memory block is smaller than the minimum page identifier or the identifier corresponding to the current flash memory block is greater than the maximum page identifier, then the current flash memory block is set to the flash memory block corresponding to the minimum page identifier.
[0053] The information storage process also includes a length comparison step and a block erasing step. The length comparison step can be to compare the information length with the remaining storage space of the current flash memory block. When the information length is less than the remaining storage space, jump to the step of generating the boot information containing the storage address. When the information length is greater than or equal to the remaining storage space, jump to the step of using the flash memory block corresponding to the identifier corresponding to the current flash memory block as the target flash memory block.
[0054] The block erasing step may be to determine the storage address to be 0 if the identifier corresponding to the current flash memory block is the same as the end identifier of the bucket storage and the information length is still greater than or equal to the remaining storage space.
[0055] When it is detected that the storage address is 0, the flash memory block corresponding to the current page identifier in the bucket storage is erased, and the flash memory block corresponding to the current page identifier is set as the target flash memory block. The process returns to execute the steps of obtaining the storage end address of the target flash memory block and the storage length of the flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information. It should be noted that the erasing operation of the flash memory is performed in units of one flash memory block, that is, all data in one flash memory block is erased.
[0056] In one embodiment, the flash memory block may not adopt storage constraints. When the storage constraints are not adopted, the information storage process does not include the above-mentioned block erasing step.
[0057] This embodiment sets a bucket storage constraint and a remaining storage space constraint, and can initialize the current flash memory block when the corresponding identifier of the current flash memory block does not meet the bucket storage constraint. When all flash memory blocks cannot meet the remaining storage space constraint, the content of the flash memory block corresponding to the minimum page identifier is erased, thereby erasing the earliest stored information and retaining the latest information, thereby improving the utilization rate of the flash memory storage space.
[0058] The above-mentioned steps of obtaining the information length of the information to be stored and generating the boot information including the storage address when the information length is less than the remaining storage space, by comparing the information length and the remaining storage space, screen out the appropriate flash memory block for storing the information to be stored, avoiding invalid attempts and improving storage efficiency.
[0059] Step S103: storing the boot information in the flash memory block.
[0060] The starting address of the boot information storage may refer to the address corresponding to the first bit of the boot information when it is stored, which is the next bit after the storage end address.
[0061] Specifically, the process of storing the boot information may be to correspond the first bit of the boot information to the starting address of the boot information storage, and write the boot information in sequence.
[0062] Optionally, if the storage mode of the target flash memory block is chain storage, the storage end address is the data storage end address;
[0063] According to the storage address, storing the information to be stored to the corresponding address includes:
[0064] Storing boot information in flash memory blocks includes:
[0065] Determine the last bit of the data storage end address as the starting address for boot information storage;
[0066] The boot information is stored in the flash memory block according to the starting address of the boot information storage.
[0067] Among them, chain storage can refer to a storage method in which the boot information is stored together with the information to be stored starting from the starting address of the flash memory block in positive order, that is, the starting address of the boot information corresponding to the information to be stored is one digit after the end address of the previous data storage.
[0068] Specifically, if Figure 2As shown in the figure, it is a structural diagram of a chain storage method. In the figure, the boot information 1 is stored at the starting position of the flash memory block, and the data information 1 corresponding to the boot information 1 is stored after the boot information 1, that is, the first bit of the data information 1 is the bit after the last bit of the boot information 1, and the first bit of the next boot information corresponds to the bit after the data storage end address, that is, the first bit of the boot information 2 corresponds to the bit after the last bit of the data information 1, and the boot information is written in sequence. The above storage method is a chain storage method. For example, if the data storage end address is 00000000F0, then the starting address of the boot information storage is 00000000F1. It should be noted that if the flash memory address of any of the above addresses in the flash memory is determined, it is necessary to add the product of the flash memory block identifier and the maximum storage length of the flash memory block to the address.
[0069] This embodiment provides a method for determining the boot information storage start address under chain storage, so that the boot information storage in this embodiment can be implemented when the flash memory block storage method is chain storage, thereby improving the generalization of the flash memory storage method.
[0070] Optionally, if the storage mode of the target flash memory block is reverse order storage, the storage end address includes the boot information storage end address;
[0071] Storing boot information in flash memory blocks includes:
[0072] Determine the last bit of the boot information storage end address as the boot information storage start address;
[0073] The boot information is stored in the flash memory block according to the starting address of the boot information storage.
[0074] The reverse order storage may refer to a storage method in which the boot information is stored in positive order starting from the start address of the flash memory block, and the information to be stored is stored in reverse order starting from the end address of the flash memory block.
[0075] Specifically, if Figure 3As shown in the figure, it is a structural diagram of a reverse storage method. In the figure, boot information 1 is stored at the starting position of the flash memory block, and the first bit of the next boot information corresponds to the next bit of the boot information storage end address, that is, the first bit of boot information 2 corresponds to the next bit of the last bit of boot information 1, and the boot information is written in sequence. The above storage method is the storage method of boot information in the reverse storage method. For example, assuming that the storage starting address of the previous boot information is 0000000000, and the boot information length in this embodiment is fixed at 8 bytes, then the storage end address of the previous boot information is 0000000007, and the starting address of the boot information storage of the information to be stored is 0000000008. It should be noted that if the flash memory address of any of the above addresses in the flash memory is determined, it is necessary to add the product of the flash memory block identifier and the maximum storage length of the flash memory block to the address.
[0076] This embodiment provides a method for determining the starting address of boot information storage in reverse order storage, so that the boot information storage in this embodiment can be implemented when the flash memory block is stored in reverse order, thereby improving the generalization of the flash memory storage method.
[0077] The above step of storing the guide information in the flash memory block can guide the storage of the information to be stored and improve the storage efficiency of the information to be stored.
[0078] Step S204: store the information to be stored in the corresponding address according to the storage address.
[0079] The corresponding address of the information to be stored may refer to each address included in the target segment storage space determined according to the storage address of the information to be stored.
[0080] Specifically, the information storage process of the information to be stored can be to determine the starting address and ending address of the target segment storage space corresponding to the information to be stored based on the storage address of the information to be stored, correspond the starting bit of the information to be stored to the starting address of the target segment storage space, correspond the ending bit of the information to be stored to the ending address of the target segment storage space, and store each bit of data in the information to be stored in sequence to each corresponding address included in the target segment storage space.
[0081] The information to be stored includes the information data to be stored and the information check. In this embodiment, the length of the information check is 2 bytes. The length of the information data to be stored is set to n bytes, then the length of the information to be stored is n+2 bytes. The information check can refer to a cyclic redundancy check (CRC), which is used to ensure the accuracy of the information to be stored when it is read after storage.
[0082] Optionally, if the storage mode of the target flash memory block is chain storage, the storage end address is the data storage end address;
[0083] According to the storage address, storing the information to be stored to the corresponding address includes:
[0084] Shifting the data storage end address backward by the boot information length to obtain a first target address, and determining the last digit of the first target address as the storage address;
[0085] According to the storage address, the information to be stored is stored in the corresponding address.
[0086] The first target address may refer to the end address after the boot information corresponding to the information to be stored is stored.
[0087] Specifically, in the chain storage mode, such as Figure 2 As shown, the process of obtaining the data address can be to add the data storage end address and the boot information length to obtain the first target address, and then add one bit to the first target address to obtain the storage address. For example, assuming that the data storage end address is 00000000F0, the first target address is 00000000F8, and the storage address is 00000000F9. It should be noted that if the flash memory address of any of the above addresses in the flash memory is determined, it is necessary to add the product of the flash block identifier and the maximum storage length of the flash block to the address.
[0088] This embodiment provides a method for determining the storage address corresponding to the information to be stored under chain storage, so that the storage of the information to be stored in this embodiment can be implemented when the storage method of the flash memory block is chain storage, thereby improving the generalization of the flash memory storage method.
[0089] Optionally, if the storage mode of the target flash memory block is reverse order storage, the storage end address includes the data storage end address;
[0090] According to the storage address, storing the information to be stored to the corresponding address includes:
[0091] Shifting the data storage end address forward by the length of the information to be stored to obtain a second target address, and determining the second target address as the storage address;
[0092] According to the storage address, the information to be stored is stored in the corresponding address.
[0093] The second target address may refer to a starting address of the target segment storage space before the data storage end address.
[0094] Specifically, the first bit of the last stored information is determined as the data storage end address, such as Figure 3As shown, in the reverse storage mode, the first bit of data information 1 is subtracted from the information length of data information 2 to obtain the first bit address of data information 2, that is, the process of obtaining the data address can be to subtract the data storage end address from the length of the information to be stored to obtain the second target address, and use the second target address as the storage address. The above storage method is the storage method of data information in the reverse storage mode. For example, assuming that the data storage end address is FFFFFFFFF0 and the length of the information to be stored is 00000000F0, the second target address is FFFFFFFF00, and the storage address is FFFFFFFF00. It should be noted that if the flash memory address of any of the above addresses in the flash memory is determined, it is necessary to add the product of the flash block identifier and the maximum storage length of the flash block to the address.
[0095] This embodiment provides a method for determining the storage address corresponding to the information to be stored in a reverse order storage mode, so that the storage of the information to be stored in this embodiment can be implemented when the storage mode of the flash memory block is reverse order storage, thereby improving the generalization of the flash memory storage method.
[0096] The above step of storing the information to be stored at the corresponding address according to the storage address can avoid the waste of flash memory storage space caused by fixed-length storage, thereby improving the space utilization of the flash memory storage.
[0097] This embodiment avoids wasting storage space by selecting a target flash memory block with a length that matches the length of the information to be stored, and stores the information to be stored and the corresponding boot information in the same target flash memory block, avoiding residual boot information after the stored information is erased, thereby improving the utilization of the flash memory storage space.
[0098] See also Figure 4 , is a flow chart of a flash memory storage method for information provided in the second embodiment of the present invention. The server also has the function of generating boot information. The boot information can be basic boot information or multiple boot information.
[0099] When the boot information is basic boot information, the process of generating the boot information is to directly use the storage address as the boot information;
[0100] When the guidance information is multiple guidance information, the server also has the functions of reading guidance information, reading guidance address, reading information, searching information number, querying guidance information and querying information.
[0101] The process of generating boot information includes:
[0102] Step S401: Determine that a preset first flag value is an information flag, and change it to a preset second flag value after the information to be stored is read.
[0103] Step S402: determining the corresponding information number according to the storage sequence of the information to be stored.
[0104] Step S403: determining that the information length of the information to be stored is the data length.
[0105] Step S404: The sum of the information number, data length and storage address is determined as the boot check.
[0106] Step S405: concatenate the information flag, boot check, information number, data length and storage address to obtain boot information.
[0107] The information flag is used to indicate the reading status of the information to be stored after storage.
[0108] The information number is used to compare with the query number sent by the user after the user sends a query instruction, and the query result is determined based on the comparison result.
[0109] The data length is used to compare with a preset length threshold after the user sends a read instruction, and determine whether to stop reading based on the comparison result.
[0110] The boot check is used to compare the sum of the information number, data length and storage address actually obtained after the user sends a read instruction, and determine whether to stop reading based on the comparison result.
[0111] Specifically, in this embodiment, the length of the information flag is 1 byte. When the information flag is the first flag value, it indicates that the information to be stored has not been read after storage. When the information flag is the second flag value, it indicates that the information to be stored has been read after storage. When the read information flag is different from both the first flag value and the second flag value, it indicates that an error occurs in the information flag, and a flag error result is returned. In this embodiment, the first flag value is set to 1 and the second flag value is set to 0.
[0112] The length of the information number is 2 bytes and increases in the order in which the information is stored. If the comparison result between the query number and the information number is consistent, it means the query is successful; otherwise, it means the query fails.
[0113] The data length is 2 bytes. The data length may refer to the total number of bytes of the data to be stored and the data check. When the data length is greater than or equal to the preset length threshold, reading is stopped and a length abnormality result is returned. In this embodiment, the length threshold is set to 2000. The implementer can adjust the length threshold according to actual conditions.
[0114] The length of the boot check is 2 bytes. The boot check may refer to the sum of the information number, information length and storage address. When the boot check is different from the sum of the information number, data length and storage address actually obtained, reading is stopped.
[0115] The length of the storage address is 2 bytes, and the storage address may refer to the starting address of the target segment storage space in the remaining storage space.
[0116] It should be noted that the above-mentioned information flag, information number, data length, boot check and storage address length can be adjusted according to actual conditions.
[0117] The information reading process can be that after the information to be stored is stored in the target flash memory block, a query instruction or a read instruction sent by the user is received, and after receiving the query instruction or the read instruction, the process jumps to the boot information position of the first information stored in the flash memory to verify the boot information, that is, to verify the information flag, the boot check and the information length respectively to avoid querying or reading wrong information. When the verification is passed, the storage address of the target information is returned.
[0118] The process of querying boot information and reading boot information can be that after the information to be stored is stored in the target flash memory block, a query instruction or a read instruction sent by the user is received, and after receiving the query instruction or the read instruction, the process jumps to the boot information position of the first information stored in the flash memory to verify the boot information, that is, to verify the information flag, the boot check and the information length respectively to avoid querying or reading wrong information. When the verification is passed, the query result or the read result of the boot information is returned.
[0119] The information query process and the information search number process can be that after the information to be stored is stored in the target flash memory block, a query instruction or search instruction sent by the user is received, and after receiving the query instruction or read instruction, the process jumps to the boot information position of the first information stored in the flash memory to verify the boot information. When the verification passes, the query number and information number in the query instruction or search instruction are compared.
[0120] The process of reading the boot address may be that when the verification of the above boot information fails or when the comparison results of the query number and information number in the above query instruction or search instruction are inconsistent, it is necessary to jump to the position of the next boot information and verify the boot information again until the comparison results are consistent or the next boot information does not exist.
[0121] This embodiment uses multiple pieces of information to form the guide information of the information to be stored, so as to facilitate the rapid and accurate query and reading of the information to be stored after it is stored, thereby improving the efficiency and accuracy of information reading.
[0122] The flash memory storage method corresponding to the information of the above embodiment, Figure 5A block diagram illustrating the structure of a flash memory storage device for information provided in a third embodiment of the present invention is provided. This flash memory storage device is applied to a server. A computer device corresponding to the server is connected to a corresponding flash memory and is capable of reading the end address and length of each flash memory block in the flash memory. The server also has read and write permissions for the flash memory. For ease of illustration, only the portion relevant to this embodiment of the present invention is shown.
[0123] See also Figure 5 , the flash memory storage device comprises:
[0124] The remaining space calculation module 51 is used to obtain the storage end address of the target flash memory block and the storage length of the flash memory block, and calculate the remaining storage space of the flash memory block in combination with the fixed length of the boot information;
[0125] A guide information generating module 52 is configured to obtain the length of the information to be stored and, if the length is less than the remaining storage space, generate guide information including a storage address, where the storage address is the starting address of the target segment storage space in the remaining storage space;
[0126] The boot information storage module 53 is used to store the boot information in the flash memory block, and the boot information storage start address is the last digit of the storage end address;
[0127] The information storage module 54 is used to store the information to be stored in the corresponding address according to the storage address.
[0128] Optionally, in the remaining space calculation module 51:
[0129] If the information length is greater than or equal to the remaining storage space, then according to the identifier corresponding to the current flash memory block, the flash memory block corresponding to the last digit of the identifier is used as the target flash memory block;
[0130] Return to the step of obtaining the storage end address and storage length of the target flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information, until the identifier corresponding to the current flash memory block is the same as the end identifier of the bucket storage.
[0131] Optionally, the guidance information generating module 52 includes:
[0132] An information flag determining unit, configured to determine a preset first flag value as an information flag, the information flag being used to represent a reading condition of the information to be stored after being stored, and changing to a preset second flag value after the information to be stored is read;
[0133] An information number determination unit is used to determine the corresponding information number according to the storage sequence of the information to be stored. The information number is used to compare with the query number sent by the user after the user sends a query instruction, and determine the query result according to the comparison result;
[0134] a data length determining unit, configured to determine the information length of the information to be stored as the data length, the data length being used to compare with a preset length threshold after the user sends a read instruction, and to determine whether to stop reading based on the comparison result;
[0135] a boot check determination unit, configured to determine the sum of the information number, data length, and storage address as a boot check, wherein the boot check is used to compare the sum of the information number, data length, and storage address actually obtained after the user sends a read instruction, and to determine whether to stop reading based on the comparison result;
[0136] The boot information splicing unit is used to splice the information flag, boot check, information number, data length and storage address to obtain the boot information.
[0137] Optionally, in the above-mentioned guidance information storage module 53:
[0138] If the storage mode of the target flash memory block is chain storage, the storage end address is the data storage end address;
[0139] Storing boot information in flash memory blocks includes:
[0140] Determine the last bit of the data storage end address as the starting address for boot information storage;
[0141] The boot information is stored in the flash memory block according to the starting address of the boot information storage.
[0142] Optionally, in the above-mentioned guidance information storage module 53:
[0143] If the storage mode of the target flash memory block is reverse order storage, the storage end address includes the boot information storage end address;
[0144] Storing boot information in flash memory blocks includes:
[0145] Determine the last bit of the boot information storage end address as the boot information storage start address;
[0146] The boot information is stored in the flash memory block according to the starting address of the boot information storage.
[0147] Optionally, in the information storage module 54:
[0148] If the storage mode of the target flash memory block is chain storage, the storage end address is the data storage end address;
[0149] According to the storage address, storing the information to be stored to the corresponding address includes:
[0150] Shifting the data storage end address backward by the boot information length to obtain a first target address, and determining the last digit of the first target address as the storage address;
[0151] According to the storage address, the information to be stored is stored in the corresponding address.
[0152] Optionally, in the information storage module 54:
[0153] If the storage mode of the target flash memory block is reverse order storage, the storage end address includes the data storage end address;
[0154] According to the storage address, storing the information to be stored to the corresponding address includes:
[0155] Shifting the data storage end address forward by the length of the information to be stored to obtain a second target address, and determining the second target address as the storage address;
[0156] According to the storage address, the information to be stored is stored in the corresponding address.
[0157] It should be noted that the information interaction, execution process, etc. between the above-mentioned modules and units are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0158] Figure 6 This is a schematic diagram of the structure of a computer device provided in the fourth embodiment of the present invention. Figure 6 As shown, the computer device of this embodiment includes: at least one processor ( Figure 6 Only one is shown), a memory, and a computer program stored in the memory and executable on at least one processor, wherein when the processor executes the computer program, the steps of any of the above-mentioned flash memory storage method embodiments are implemented.
[0159] The computer device may include, but is not limited to, a processor and a memory. It will be understood by those skilled in the art that Figure 6 The above is merely an example of a computer device and does not constitute a limitation on the computer device. The computer device may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include a network interface, a display screen, and an input device.
[0160] The processor may be a CPU, or other general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. A general-purpose processor may be a microprocessor, or any conventional processor.
[0161] The memory includes a readable storage medium, an internal memory, etc., wherein the internal memory can be the memory of a computer device, and the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the readable storage medium. The readable storage medium can be the hard disk of the computer device, and in other embodiments, it can also be an external storage device of the computer device, for example, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device. Furthermore, the memory can also include both the internal storage unit of the computer device and the external storage device. The memory is used to store the operating system, application programs, boot loaders (BootLoader), data, and other programs, such as the program code of the computer program. The memory can also be used to temporarily store data that has been output or is about to be output.
[0162] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned device can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, it can implement the steps of the above-mentioned method embodiment. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include at least: any entity or device capable of carrying computer program code, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0163] The present invention may implement all or part of the processes in the above-mentioned method embodiments, and may also be completed through a computer program product. When the computer program product runs on a computer device, the computer device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0164] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0165] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0166] In the embodiments provided by the present invention, it should be understood that the disclosed apparatus / computer equipment and methods can be implemented in other ways. For example, the apparatus / computer equipment embodiments described above are merely illustrative. For example, the division of modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0167] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0168] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A method for storing information in a flash memory, characterized in that: The method comprises: Obtaining the storage end address of the target flash memory block and the storage length of the flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information; obtaining an information length of information to be stored, and generating boot information including a storage address when the information length is less than the remaining storage space, wherein the storage address is a starting address of a target segment storage space in the remaining storage space; Storing the boot information in the flash memory block, wherein the boot information storage start address is the next digit after the storage end address; According to the storage address, the information to be stored is stored in the corresponding address; The generating of the boot information including the storage address includes: Determine a preset first flag value as an information flag, the information flag is used to represent the reading status of the information to be stored after storage, and change to a preset second flag value after the information to be stored is read; Determine the corresponding information number according to the storage sequence of the information to be stored, and compare the information number with the query number sent by the user after the user sends the query instruction, and determine the query result according to the comparison result; Determining the information length of the information to be stored as the data length, wherein the data length is used to compare with a preset length threshold after the user sends a read instruction, and determining whether to stop reading according to the comparison result; determining the sum of the information number, the data length, and the storage address as a boot check, wherein the boot check is used to compare the sum of the information number, the data length, and the storage address actually obtained after the user sends a read instruction, and determining whether to stop reading according to the comparison result; The information flag, the boot check, the information number, the data length and the storage address are concatenated to obtain the boot information.
2. The flash memory storage method according to claim 1, wherein: If the message length is greater than or equal to the remaining storage space, then: According to the identifier corresponding to the current flash memory block, the flash memory block corresponding to the last digit of the identifier is used as the target flash memory block; Return to executing the step of obtaining the storage end address of the target flash memory block and the storage length of the flash memory block, and calculating the remaining storage space of the flash memory block in combination with the fixed length of the boot information, until the identifier corresponding to the current flash memory block is the same as the end identifier of the bucket storage.
3. The flash memory storage method according to claim 1, wherein: If the storage mode of the target flash memory block is chain storage, the storage end address is the data storage end address; The storing the boot information in the flash memory block comprises: Determine the last digit of the data storage end address as the starting address for storing the boot information; The boot information is stored in the flash memory block according to the starting address of the boot information storage.
4. The flash memory storage method according to claim 1, wherein: If the storage mode of the target flash memory block is reverse storage, the storage end address includes the boot information storage end address; The storing the boot information in the flash memory block comprises: Determine the last bit of the boot information storage end address as the boot information storage start address; The boot information is stored in the flash memory block according to the starting address of the boot information storage.
5. The flash memory storage method according to claim 1, wherein: If the storage mode of the target flash memory block is chain storage, the storage end address is the data storage end address; According to the storage address, storing the information to be stored in the corresponding address includes: Shifting the data storage end address backward by the boot information length to obtain a first target address, and determining the last digit of the first target address as the storage address; According to the storage address, the information to be stored is stored in the corresponding address.
6. The flash memory storage method according to claim 1, wherein: If the storage mode of the target flash memory block is reverse storage, the storage end address includes a data storage end address; According to the storage address, storing the information to be stored in the corresponding address includes: Shifting the data storage end address forward by the information length of the information to be stored to obtain a second target address, and determining the second target address as the storage address; According to the storage address, the information to be stored is stored in the corresponding address.
7. A flash memory storage device for information, characterized in that: The flash memory storage device comprises: A remaining space calculation module is used to obtain the storage end address of the target flash memory block and the storage length of the flash memory block, and calculate the remaining storage space of the flash memory block in combination with the fixed length of the boot information; a boot information generating module, configured to obtain the information length of the information to be stored, and, when the information length is less than the remaining storage space, generate boot information including a storage address, wherein the storage address is a starting address of a target segment storage space in the remaining storage space; A boot information storage module, configured to store the boot information in the flash memory block, wherein the boot information storage start address is the next digit after the storage end address; An information storage module, configured to store the information to be stored in a corresponding address according to the storage address; The guidance information generation module includes: An information flag determining unit, configured to determine a preset first flag value as an information flag, wherein the information flag is used to represent a reading condition of the information to be stored after storage, and to change the value of the preset second flag after the information to be stored is read; An information number determining unit, configured to determine a corresponding information number according to a storage sequence of the information to be stored, wherein the information number is used to compare with a query number sent by the user after the user sends a query instruction, and determine a query result according to the comparison result; a data length determining unit, configured to determine the information length of the information to be stored as the data length, wherein the data length is used to compare with a preset length threshold after the user sends a read instruction, and to determine whether to stop reading according to the comparison result; a boot check determination unit, configured to determine the sum of the information number, the data length, and the storage address as a boot check, wherein the boot check is used to compare the sum of the information number, the data length, and the storage address actually obtained after the user sends a read instruction, and determine whether to stop reading based on the comparison result; The boot information splicing unit is used to splice the information flag, the boot check, the information number, the data length and the storage address to obtain the boot information.
8. A computer device, characterized in that: The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the flash memory storage method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the flash memory storage method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Storage address space to NVM address, span, and length mapping / converting
CN103942114A
Data access method, terminal and computer readable storage medium
CN112506918A