Data storage method and device, electronic equipment and computer readable storage medium

By dividing the index area and data area in the memory sector and writing it directly into the data area, the problems of low efficiency and short memory life in the prior art are solved, and the effect of saving space and extending memory life is achieved.

CN119225638APending Publication Date: 2024-12-31GUANGDONG TRANSTEK MEDICAL ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411193928.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

Existing data storage methods are inefficient, waste storage space and short memory service life, requiring frequent erasing of sector data, resulting in memory corruption.

Method used

Each sector of the memory divides the index area and the data area, and determines the remaining storage space and storage address through the index information, and writes it directly to the data area without erasing the entire sector, avoiding backup of data with the help of the cache area.

Benefits of technology

Save storage space, improve data writing efficiency, extend memory service life, reduce erases, and improve system efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225638A_ABST
    Figure CN119225638A_ABST
Patent Text Reader

Abstract

The invention provides a data storage method and device, electronic equipment and a computer readable storage medium, and relates to the field of data storage. Each sector of the memory is divided into an index area and a data area, index information stored in the index area is used for representing the data writing condition of the data area, and when target data is written into any sector of the memory, the remaining storage space of the data area can be determined according to the index information stored in the index area; and when the residual storage space is greater than or equal to the data length of the target data, determining a storage address of the target data in the data area according to the index information, writing the target data into the data area according to the storage address, and updating the index information stored in the index area according to the data length of the target data. According to the method, when the data is written, the data of the whole sector does not need to be erased firstly, the data is directly written into the data area of the sector, and the data does not need to be backed up by means of a cache area, so that the storage space can be saved, the data writing efficiency is improved, and the service life of a memory is prolonged.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data storage, and in particular to a data storage method, device, electronic device and computer-readable storage medium. Background Art

[0002] With the rapid development of the information age, the demand for data storage in related electronic devices is increasing. For memories with small storage space, data usually needs to be erased before writing. For example, flash memory (FLASH) can be read and written by bytes, but only the entire sector (512 bytes) can be erased. When writing or updating data to a sector, the data of the entire sector needs to be erased first, and then written. If you need to keep the original data, you also need to read the original data and copy it to the cache area, and then update the data in the cache area. After erasing the data of the entire sector, rewrite the updated data in the cache area into the erased sector.

[0003] The above data storage method needs to go through the four steps of reading, modifying, erasing and writing, and needs to use the cache area to back up the original data, which not only reduces the efficiency of writing data, but also wastes storage space; each time new data is written, the data of the entire sector needs to be erased. The memory has a limited number of erase times, and frequent erasing operations on the memory will reduce the service life of the memory. Summary of the invention

[0004] In view of this, an object of the present invention is to provide a data storage method, device, electronic device and computer-readable storage medium to solve the problems of wasted storage space, low efficiency and short memory service life in existing data storage methods.

[0005] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows:

[0006] In a first aspect, the present invention provides a data storage method, the method comprising:

[0007] When writing target data to any sector of the memory, determining the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector; the index information is used to characterize the data writing status of the data area;

[0008] When the remaining storage space is greater than or equal to the data length of the target data, determining the storage address of the target data in the data area according to the index information;

[0009] Writing the target data into the data area according to the storage address;

[0010] The index information stored in the index area is updated according to the data length of the target data.

[0011] In an optional implementation, the index area is divided into a plurality of identification storage units, the data area is divided into a plurality of data storage units, and the plurality of identification storage units correspond to the plurality of data storage units one by one; the index information includes identification information stored in each identification storage unit, and the identification information is used to indicate whether the data storage unit corresponding to the identification storage unit is written with data; and determining the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector includes:

[0012] Determine the storage space occupied by the data storage unit in the data area where the data has been written according to the identification information stored in each identification storage unit in the index area;

[0013] The remaining storage space of the data area is determined according to the total storage space of the data area and the storage space occupied by the data storage units in the data area into which data has been written.

[0014] In an optional implementation manner, different identification storage units correspond to different index numbers respectively; and determining the storage space occupied by the data storage unit in the data area where data has been written according to the identification information stored in each of the identification storage units in the index area comprises:

[0015] The identification information stored in each identification storage unit in the index area is read in sequence to obtain a first index number of an identification storage unit whose identification information is a first preset value; when the identification information is the first preset value, it indicates that the data storage unit corresponding to the identification storage unit where the identification information is located has not been written with data;

[0016] The storage space occupied by the data storage unit in the data area where the data has been written is calculated according to the first index number.

[0017] In an optional implementation manner, determining the storage address of the target data in the data area according to the index information includes:

[0018] The storage address of the target data in the data area is calculated according to the first index number and the starting address of the data area.

[0019] In an optional implementation manner, updating the index information stored in the index area according to the data length of the target data includes:

[0020] Determine a second index number according to the data length of the target data and the first index number; the second index number is the index number of the identification storage unit corresponding to the last data storage unit where the target data is written;

[0021] The identification information stored in the identification storage unit with index numbers of the first index number, the second index number, and an index number between the first index number and the second index number in the index area is written as a second preset value; when the identification information is the second preset value, it indicates that data has been written into the data storage unit corresponding to the identification storage unit where the identification information is located.

[0022] In an optional embodiment, the method further comprises:

[0023] When the remaining storage space is smaller than the data length of the target data, erasing the data currently stored in the sector;

[0024] After erasing the data currently stored in the sector, the target data is written into the sector.

[0025] In an optional embodiment, the method further comprises:

[0026] When the remaining storage space is less than the data length of the target data and the remaining storage space is greater than 0, the first data in the target data is written into the data area, and the second data of the target data is written into the next sector adjacent to the sector; the size of the first data is equal to the remaining storage space, and the second data is the remaining data in the target data except the first data.

[0027] In a second aspect, the present invention provides a data storage device, the device comprising:

[0028] A remaining space determination module, used to determine the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector when writing target data to any sector of the memory; the index information is used to characterize the data writing status of the data area;

[0029] A storage address determination module, configured to determine a storage address of the target data in the data area according to the index information when the remaining storage space is greater than or equal to the data length of the target data;

[0030] A data writing module, used for writing the target data into the data area according to the storage address;

[0031] The index information updating module is used to update the index information stored in the index area according to the data length of the target data.

[0032] In a third aspect, the present invention provides an electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the data storage method as described in any one of the aforementioned embodiments.

[0033] In a fourth aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the data storage method as described in any of the aforementioned embodiments are implemented.

[0034] The data storage method, device, electronic device and computer-readable storage medium provided by the embodiments of the present invention divide each sector of the memory into an index area and a data area. The index information stored in the index area is used to characterize the data writing status of the data area. When writing target data to any sector of the memory, the remaining storage space of the data area can be determined according to the index information stored in the index area; when the remaining storage space is greater than or equal to the data length of the target data, the storage address of the target data in the data area is determined according to the index information, the target data is written to the data area according to the storage address, and the index information stored in the index area is updated according to the data length of the target data. When writing data, this method does not need to erase the data of the entire sector first, but directly writes data to the data area of ​​the sector, and does not need to use the cache area to back up data, so it can save storage space, improve the efficiency of writing data, and extend the service life of the memory.

[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0037] Figure 1 A schematic diagram showing a flow chart of a data storage method provided by an embodiment of the present invention;

[0038] Figure 2 A schematic diagram showing a sector being divided into an index area and a data area;

[0039] Figure 3 A schematic diagram showing each bit in the index area corresponding to each byte in the data area;

[0040] Figure 4 Another schematic diagram showing each bit in the index area corresponding to each byte in the data area;

[0041] Figure 5 Another schematic diagram of a data storage method according to an embodiment of the present invention is shown;

[0042] Figure 6 Another schematic diagram of a data storage method provided by an embodiment of the present invention is shown;

[0043] Figure 7 A functional module diagram of a data storage device provided by an embodiment of the present invention is shown;

[0044] Figure 8 A structural block diagram of an electronic device provided by an embodiment of the present invention is shown.

[0045] Icons: 100 - electronic device; 110 - memory; 120 - processor; 130 - communication module; 600 - data storage device; 610 - remaining space determination module; 620 - storage address determination module; 630 - data writing module; 640 - index information updating module. DETAILED DESCRIPTION

[0046] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0047] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.

[0048] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0049] Existing data storage methods usually require four steps of reading, modifying, erasing, and writing, which are relatively inefficient. If you encounter some environments with high timeliness requirements, the efficiency of the entire system will be reduced; every time new data is written, the data of the entire sector needs to be erased, and the memory has a limit on the number of erase times, generally ranging from tens of thousands to millions; if you need to update data frequently, the service life of the memory will be greatly reduced; in addition, before erasing data, it is usually necessary to use other storage space to back up the original data, which takes up resources.

[0050] In order to solve the problems of wasting storage space, low efficiency and short service life of memory in existing data storage methods, the embodiments of the present invention provide a data storage method, device, electronic device and computer-readable storage medium. When writing data, the method does not need to erase the data of the entire sector first, but directly writes data to the data area of ​​the sector, and does not need to back up data with the help of a cache area. Therefore, it can save storage space, improve the efficiency of writing data, and extend the service life of the memory.

[0051] Hereinafter, various embodiments of the present invention will be described in detail with reference to the accompanying drawings.

[0052] Please refer to Figure 1 , is a flow chart of a data storage method provided by an embodiment of the present invention. It should be noted that the data storage method of the embodiment of the present invention is not based on Figure 1 It should be understood that in other embodiments, the order of some steps in the data storage method of the embodiment of the present invention can be interchanged according to actual needs, or some steps can be omitted or deleted. The data storage method can be applied to electronic devices such as smart phones, tablet computers, and PCs (Personal Computers). Figure 1 The specific process shown is described in detail.

[0053] Step S101, when writing target data to any sector of the memory, the remaining storage space of the data area of ​​the sector is determined according to the index information stored in the index area of ​​the sector; the index information is used to represent the data writing status of the data area.

[0054] In this embodiment, the storage space of each sector of the memory can be adjusted in advance, that is, an index area and a data area are divided in each sector, the index area is used to store index information representing the data writing status of the data area, and the data area is used to store the data actually written into the sector. When it is necessary to write target data to any sector of the storage area, the index area can be traversed first, and the actual usage of the data area of ​​the sector can be determined according to the index information stored in the index area, so as to determine the remaining storage space of the data area.

[0055] Step S102: when the remaining storage space is greater than or equal to the data length of the target data, determine the storage address of the target data in the data area according to the index information.

[0056] In this embodiment, when the remaining storage space in the data area of ​​the sector is greater than or equal to the data length of the target data to be written, it indicates that the target data does not exceed the capacity of the data area, and the target data can be written into the data area of ​​the sector. Since the index information can represent the data writing situation of the data area, it can be determined which addresses in the data area have been written with data and which addresses have not been written with data in combination with the data writing situation of the data area, thereby further determining the address where the target data should be written into the data area, that is, the storage address of the target data in the data area.

[0057] Step S103, writing the target data into the data area according to the storage address.

[0058] In this embodiment, after the storage address of the target data in the data area is determined, the target data can be written into the data area of ​​the sector according to the storage address.

[0059] Step S104: update the index information stored in the index area according to the data length of the target data.

[0060] In this embodiment, after new data (target data) is written to the data area of ​​the sector, the actual usage of the data area of ​​the sector will change. Since the index area is used to store index information that represents the data writing status of the data area, the index information in the index area needs to be updated accordingly to ensure that the index area records the latest data writing status of the data area. In this way, each time data is written to the sector, the latest data writing status of the data area can be accurately judged based on the index information stored in the index area, and then the data is written to the appropriate location in the data area.

[0061] It can be seen that the data storage method provided by the embodiment of the present invention divides each sector of the memory into an index area and a data area. The index information stored in the index area is used to characterize the data writing status of the data area. When writing target data to any sector of the memory, the remaining storage space of the data area can be determined according to the index information stored in the index area; when the remaining storage space is greater than or equal to the data length of the target data, the storage address of the target data in the data area is determined according to the index information, the target data is written to the data area according to the storage address, and the index information stored in the index area is updated according to the data length of the target data. When writing data, this method does not need to erase the data of the entire sector first, but directly writes data to the data area of ​​the sector, and does not need to use the cache area to back up data, so it can save storage space, improve the efficiency of writing data, and extend the service life of the memory.

[0062] In one embodiment, the index area of ​​a sector can be divided into multiple identification storage units, and the data area of ​​a sector can be divided into multiple data storage units, and the multiple identification storage units correspond to the multiple data storage units one by one. Among them, the size of the identification storage unit and the data storage unit (the storage space occupied) can be set according to actual needs. For example, each identification storage unit can be set as a bit in the index area, and each data storage unit can be set as a byte in the data area. Each identification storage unit is used to store identification information, and each data storage unit is used to store written data. Then the index information stored in the index area includes the identification information stored in each identification storage unit, and the identification information is used to characterize whether the data storage unit corresponding to the identification storage unit is written with data. Based on this, according to the identification information stored in each identification storage unit in the index area of ​​the sector, the data storage unit in the data area to which data has been written and the data storage unit to which data has not been written can be determined, and then the remaining storage space in the data area of ​​the sector can be determined.

[0063] Optionally, in the above-mentioned step S101, the remaining storage space of the data area of ​​the sector is determined based on the index information stored in the index area of ​​the sector, which may specifically include: determining the storage space occupied by the data storage units in the data area where data has been written based on the identification information stored in each identification storage unit in the index area; determining the remaining storage space of the data area based on the total storage space of the data area and the storage space occupied by the data storage units in the data area where data has been written.

[0064] In this embodiment, since the size of each data storage unit is fixed, after determining the data storage unit in the data area where data has been written based on the identification information stored in each identification storage unit in the index area of ​​the sector, the storage space occupied by the data storage unit in which data has been written can be obtained, that is, the storage space currently used in the data area, and then the remaining storage space of the data area can be calculated based on the total storage space of the data area and the storage space currently used in the data area.

[0065] In one embodiment, in order to facilitate the determination of whether data is written into a data storage unit and the calculation of the storage space occupied by the data storage unit in the data area where data has been written, different identification storage units can be set to correspond to different index numbers, and different values ​​of identification information can be set to distinguish whether data storage units corresponding to the identification storage units have been written into. Based on this, the above steps determine the storage space occupied by the data storage unit in the data area where data has been written into according to the identification information stored in each identification storage unit in the index area, and specifically may include: sequentially reading the identification information stored in each identification storage unit in the index area, and obtaining the first index number of the identification storage unit whose identification information is the first preset value; when the identification information is the first preset value, it indicates that the data storage unit corresponding to the identification storage unit where the identification information is located has not been written into; and calculating the storage space occupied by the data storage unit in the data area where data has been written into according to the first index number.

[0066] In this embodiment, the search can be started from the first identification storage unit in the index area, and the identification information stored in each identification storage unit is read out in sequence. When the first identification storage unit storing the first preset value (that is, the identification information stored is the first preset value) is retrieved, the index number of the identification storage unit is determined to be the first index number and recorded. The first preset value can be set according to the characteristics of the memory. For example, for a memory that is "1" after erasure and "0" after writing, the first preset value can be set to 1. When the first identification storage unit with identification information of "1" is retrieved, the index number of the identification storage unit is determined to be the first index number; similarly, for a memory that is "0" after erasure and "1" after writing, the first preset value can be set to 0. When the first identification storage unit with identification information of "0" is retrieved, the index number of the identification storage unit is determined to be the first index number.

[0067] Since the identification storage units in the index area correspond one to one with the data storage units in the data area, the number of data storage units into which data has been written can be known by obtaining the first index number, and the size of each data storage unit is fixed, so the storage space occupied by the data storage units into which data has been written can be calculated, and combined with the total storage space of the data area, the remaining storage space of the data area can be obtained.

[0068] In one implementation, the above step S102 may specifically include: calculating the storage address of the target data in the data area according to the first index number and the starting address of the data area.

[0069] In this embodiment, the storage address of the target data in the data area can be understood as the starting address of writing the target data into the data area. Since the first index number is the index number of the identification storage unit whose first identification information in the index area is a first preset value, the data storage unit corresponding to the identification storage unit is the first data storage unit in the data area that has not been written with data. When writing the target data, writing starts from this data storage unit. The address of the data storage unit can be calculated by the first index number and the starting address of the data area.

[0070] In one embodiment, the above-mentioned step S104 may specifically include: determining the second index number based on the data length of the target data and the first index number; the second index number is the index number of the identification storage unit corresponding to the last data storage unit where the target data is written; writing the identification information stored in the identification storage units with index numbers of the first index number, the second index number, and index numbers between the first index number and the second index number in the index area as the second preset value; when the identification information is the second preset value, it indicates that the data storage unit corresponding to the identification storage unit where the identification information is located has been written with data.

[0071] In this embodiment, the number of data storage units occupied by the target data can be determined based on the data length of the target data. Since the identification storage units in the index area correspond to the data storage units in the data area one by one, the index number (i.e., the second index number) of the identification storage unit corresponding to the last data storage unit written with the target data can be determined based on the data length of the target data and the first index number. Therefore, after writing the target data to the data area, the identification storage units corresponding to the data storage units occupied by the target data in the data area are all the identification storage units with index numbers from the first index number to the second index number. By writing the identification information stored in the identification storage units with index numbers of the first index number, the second index number, and the index number between the first index number and the second index number in the index area as the second preset value, it is indicated that the data storage units corresponding to the identification storage units with index numbers of the first index number, the second index number, and the index number between the first index number and the second index number have been written with data.

[0072] In this embodiment, similar to the first preset value, the second preset value can be set according to the characteristics of the memory. For example, for a memory that is "1" after erasure and "0" after writing, the first preset value can be set to 1 and the second preset value can be set to 0; similarly, for a memory that is "0" after erasure and "1" after writing, the first preset value can be set to 0 and the second preset value can be set to 1.

[0073] The following is a detailed description of the above steps with specific examples. Figure 2For a 512-byte sector, by adjusting its storage space distribution, it can be divided into an index area and a data area. The space size of the index area is 56 bytes. Each identification storage unit is set as a bit in the index area and corresponds to each byte (data storage unit) in the data area in sequence. Since 1 byte = 8 bits, the data in the range of 57 to 504 bytes of the sector can be indexed from the 1st to 56th bytes of the index area, which corresponds to the 1st to 448th bytes of the data area. Please refer to Figure 3 , starting from the first bit of the first byte of the index area to the last bit of the last byte of the index area, index numbers 1, 2, 3, ..., 448 are assigned to each bit in sequence and recorded to obtain the index number of each identification storage unit in the index area; the data storage unit corresponding to the identification storage unit with index number 1 is the first byte of the data area (that is, the 57th byte of the sector), and so on, the data storage unit corresponding to the identification storage unit with index number 448 is the 448th byte of the data area (that is, the 504th byte of the sector).

[0074] Assuming that the first preset value is 1 and the second preset value is 0, when the first bit of the index area is 1, it indicates that the first byte of the corresponding data area has not been written with data. Conversely, when the first bit of the index area is 0, it indicates that the first byte of the corresponding data area has been written with data. Taking advantage of the fact that the memory can only write data from 1 to 0, when data needs to be written, first traverse which bit in the index area has not been written to 0, then write the corresponding data in the byte (data storage unit) of the corresponding data area, and then write 0 in the corresponding bit (identification storage unit) of the index area, indicating that the corresponding data storage unit has been written with data. Specifically, when it is necessary to write target data to a sector, retrieve the first bit of 1 in the index area, and record the corresponding index number as n (n≥1). Then the storage space occupied by the data storage unit in the data area that has been written with data is (n-1). Correspondingly, the remaining storage space of the data area is y=448-(n-1), and the unit of y is bytes. The target data to be written is x bytes. When x≤y, it indicates that the target data can be written into the data area. The starting address of the data writing is the (56+n)th byte of the sector, that is, starting from the (56+n)th byte of the sector, the target data is written into the data area, and then the bits with index numbers n to [(n+x)-1] in the index area are written to 0.

[0075] like Figure 4As shown, assuming that the data length of the target data to be written into the sector is x=3 bytes, the first two bits of the first byte of the current index area are both 0, indicating that the two bytes of the data area corresponding to these two bits (the 57th and 58th bytes of the sector) have been written with data. At this time, the first bit of the index area that is 1 is the third bit in the first byte, and the corresponding index number is n=3 (the first index number). According to the formula y=448-(n-1), the remaining storage space y=446 of the data area is calculated. Since y is greater than x, the storage address of the target data is calculated according to the formula (56+n) as the 59th byte of the sector, that is, the target data is written from the 3rd byte of the data area. After the target data is written into the data area, the bits with index numbers 3 to 5 in the index area are written from 1 to 0 according to the formula n~[(n+x)-1], indicating that the 3rd to 5th bytes in the corresponding data area (the 59th, 60th, and 61st bytes of the sector) have been written with data.

[0076] In actual applications, when the remaining storage space in the data area is less than the data length of the data to be written, it indicates that the data to be written has exceeded the storage capacity of the data area. At this time, the data can be written to an adjacent sector or the current sector can be erased and rewritten as needed. The following describes these two implementation methods.

[0077] In one embodiment, see Figure 5 , the data storage method may further include:

[0078] S501, when the remaining storage space is smaller than the data length of the target data, erasing the data currently stored in the sector; after erasing the data currently stored in the sector, writing the target data into the sector.

[0079] That is to say, when the data length of the target data is greater than the remaining storage space of the data area, the sector can be erased, and then the target data can be written into the sector according to the relevant contents of the above steps S101 to S104.

[0080] In one embodiment, see Figure 6 , the data storage method may further include:

[0081] S601, when the remaining storage space is less than the data length of the target data and the remaining storage space is greater than 0, the first data in the target data is written into the data area, and the second data of the target data is written into the next sector adjacent to the sector; the size of the first data is equal to the remaining storage space, and the second data is the remaining data in the target data except the first data.

[0082] That is to say, when the data length x of the target data is greater than the remaining storage space y of the data area, if the scheme of writing data to the adjacent sector is adopted, first determine whether the remaining storage space y of the current data area is greater than 0. When the remaining storage space y is greater than 0, it indicates that the data area of ​​the sector can continue to write data. At this time, the first data of the target data with the same size as the remaining storage space y is written to the current sector, and then the second data of the remaining size (xy) of the target data is written to the next adjacent sector. When writing data to the next sector, the relevant contents of the above steps S101 to S104 can still be referred to.

[0083] It is understandable that the existing data storage scheme needs to back up data with the help of the cache area, while the data storage method provided by the embodiment of the present invention can directly write data to the data area of ​​the sector, without the need to back up data with the help of the cache area, so it can save storage space; in the existing data storage scheme, each time new data is to be written, the data of the entire sector needs to be erased first, and the memory has a limit on the number of erasures. When the number of erasures exceeds the limit, the memory is easily damaged. The data storage method provided by the embodiment of the present invention only erases as needed when the data to be written exceeds the storage capacity of the data area, which greatly reduces the number of erasures and prolongs the service life of the memory. In addition, for the memory, when erasing, the entire sector is erased, and the time consumption is usually at the ms level; while reading and writing data in a sector usually takes μs. The existing data storage scheme needs to go through the four steps of reading, modifying, erasing, and writing, and the data must be erased before each data writing, so the efficiency is low; while the data storage method provided by the embodiment of the present invention only erases as needed when the sector is full, which reduces the number of erasures, saves time, and is more efficient.

[0084] In order to execute the corresponding steps in the above embodiments and various possible methods, a method for implementing a data storage device is given below. Figure 7 , which is a functional module diagram of a data storage device 600 provided in an embodiment of the present invention. It should be noted that the basic principle and technical effects of the data storage device 600 provided in this embodiment are the same as those of the above embodiments. For the sake of brief description, for parts not mentioned in this embodiment, reference can be made to the corresponding contents in the above embodiments. The data storage device 600 includes a remaining space determination module 610, a storage address determination module 620, a data writing module 630, and an index information updating module 640.

[0085] The remaining space determination module 610 is used to determine the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector when writing target data to any sector of the memory; the index information is used to represent the data writing status of the data area.

[0086] It can be understood that the remaining space determination module 610 can execute the above step S101.

[0087] The storage address determination module 620 is used to determine the storage address of the target data in the data area according to the index information when the remaining storage space is greater than or equal to the data length of the target data.

[0088] It can be understood that the storage address determination module 620 can execute the above step S102.

[0089] The data writing module 630 is used to write the target data into the data area according to the storage address.

[0090] It can be understood that the data writing module 630 can execute the above step S103.

[0091] The index information updating module 640 is used to update the index information stored in the index area according to the data length of the target data.

[0092] It can be understood that the index information updating module 640 can execute the above step S104.

[0093] Optionally, the index area is divided into a plurality of identification storage units, and the data area is divided into a plurality of data storage units, and the plurality of identification storage units correspond to the plurality of data storage units one by one; the index information includes identification information stored in each identification storage unit, and the identification information is used to indicate whether the data storage unit corresponding to the identification storage unit has been written with data. The remaining space determination module 610 is used to determine the storage space occupied by the data storage unit in the data area that has been written with data according to the identification information stored in each identification storage unit in the index area; and to determine the remaining storage space in the data area according to the total storage space in the data area and the storage space occupied by the data storage unit in the data area that has been written with data.

[0094] Optionally, different identification storage units correspond to different index numbers; the remaining space determination module 610 is specifically used to read the identification information stored in each identification storage unit in the index area in turn, and obtain the first index number of the identification storage unit whose first identification information is a first preset value; when the identification information is the first preset value, it indicates that the data storage unit corresponding to the identification storage unit where the identification information is located has not been written with data; and the storage space occupied by the data storage units in the data area that have been written with data is calculated according to the first index number.

[0095] Optionally, the storage address determination module 620 is specifically configured to calculate a storage address of the target data in the data area according to the first index number and the starting address of the data area.

[0096] Optionally, the index information updating module 640 is specifically used to determine the second index number based on the data length of the target data and the first index number; the second index number is the index number of the identification storage unit corresponding to the last data storage unit in which the target data is written; the identification information stored in the identification storage units in the index area having the first index number, the second index number, and the index number between the first index number and the second index number is written as the second preset value; when the identification information is the second preset value, it indicates that the data storage unit corresponding to the identification storage unit where the identification information is located has been written with data.

[0097] Optionally, the data writing module 630 is further configured to erase the data currently stored in the sector when the remaining storage space is smaller than the data length of the target data; and write the target data into the sector after erasing the data currently stored in the sector.

[0098] It can be understood that the data writing module 630 can also execute the above step S501.

[0099] Optionally, the data writing module 630 is also used to write the first data in the target data into the data area and write the second data of the target data into the next sector adjacent to the sector when the remaining storage space is less than the data length of the target data and the remaining storage space is greater than 0; the size of the first data is equal to the remaining storage space, and the second data is the remaining data in the target data except the first data.

[0100] It can be understood that the data writing module 630 can also execute the above step S601.

[0101] It can be seen that the data storage device provided by the embodiment of the present invention includes a remaining space determination module, a storage address determination module, a data writing module and an index information updating module. The remaining space determination module is used to determine the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector when writing the target data to any sector of the memory; the index information is used to characterize the data writing situation of the data area; the storage address determination module is used to determine the storage address of the target data in the data area according to the index information when the remaining storage space is greater than or equal to the data length of the target data; the data writing module is used to write the target data into the data area according to the storage address; the index information updating module is used to update the index information stored in the index area according to the data length of the target data. When writing data, the data storage device does not need to erase the data of the entire sector first, but directly writes data to the data area of ​​the sector, and does not need to use the cache area to back up data, so it can save storage space, improve the efficiency of writing data, and extend the service life of the memory.

[0102] Please refer to Figure 8, is a block diagram of an electronic device 100 provided in an embodiment of the present invention. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, the processor 120, and the communication module 130 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.

[0103] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.

[0104] The processor 120 is used to read / write data or programs stored in the memory 110 and execute corresponding functions. For example, when the computer program stored in the memory 110 is executed by the processor 120, the data storage method disclosed in the above embodiments can be implemented.

[0105] The communication module 130 is used to establish a communication connection between the electronic device 100 and other devices through a network, and to send and receive data through the network.

[0106] It should be understood that Figure 8 The structure shown is only a schematic diagram of the structure of the electronic device 100. The electronic device 100 may also include Figure 8 More or fewer components as shown, or with Figure 8 Different configurations shown. Figure 8 Each component shown in the figure can be implemented by hardware, software or a combination thereof.

[0107] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 120, the data storage method disclosed in the above embodiments is implemented.

[0108] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0109] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.

[0110] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. 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, etc. Various media that can store program codes.

[0111] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A data storage method, characterized in that: The method comprises: When writing target data to any sector of the memory, determining the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector; the index information is used to characterize the data writing status of the data area; When the remaining storage space is greater than or equal to the data length of the target data, determining the storage address of the target data in the data area according to the index information; Writing the target data into the data area according to the storage address; The index information stored in the index area is updated according to the data length of the target data.

2. The data storage method according to claim 1, characterized in that: The index area is divided into a plurality of identification storage units, and the data area is divided into a plurality of data storage units, and the plurality of identification storage units correspond to the plurality of data storage units one by one; the index information includes identification information stored in each identification storage unit, and the identification information is used to indicate whether the data storage unit corresponding to the identification storage unit is written with data; The determining, according to the index information stored in the index area of ​​the sector, the remaining storage space of the data area of ​​the sector comprises: Determine the storage space occupied by the data storage unit in the data area where the data has been written according to the identification information stored in each identification storage unit in the index area; The remaining storage space of the data area is determined according to the total storage space of the data area and the storage space occupied by the data storage units in the data area into which data has been written.

3. The data storage method according to claim 2, characterized in that: Different identification storage units correspond to different index numbers respectively; and determining the storage space occupied by the data storage unit in the data area where data has been written according to the identification information stored in each identification storage unit in the index area comprises: The identification information stored in each identification storage unit in the index area is read in sequence to obtain a first index number of an identification storage unit whose identification information is a first preset value; when the identification information is the first preset value, it indicates that the data storage unit corresponding to the identification storage unit where the identification information is located has not been written with data; The storage space occupied by the data storage unit in the data area where the data has been written is calculated according to the first index number.

4. The data storage method according to claim 3, characterized in that: Determining the storage address of the target data in the data area according to the index information includes: The storage address of the target data in the data area is calculated according to the first index number and the starting address of the data area.

5. The data storage method according to claim 3, characterized in that: The updating of the index information stored in the index area according to the data length of the target data includes: Determine a second index number according to the data length of the target data and the first index number; the second index number is the index number of the identification storage unit corresponding to the last data storage unit where the target data is written; The identification information stored in the identification storage unit with index numbers of the first index number, the second index number, and an index number between the first index number and the second index number in the index area is written as a second preset value; when the identification information is the second preset value, it indicates that data has been written into the data storage unit corresponding to the identification storage unit where the identification information is located.

6. The data storage method according to claim 1, characterized in that: The method further comprises: When the remaining storage space is smaller than the data length of the target data, erasing the data currently stored in the sector; After erasing the data currently stored in the sector, the target data is written into the sector.

7. The data storage method according to claim 1, characterized in that: The method further comprises: When the remaining storage space is less than the data length of the target data and the remaining storage space is greater than 0, the first data in the target data is written into the data area, and the second data of the target data is written into the next sector adjacent to the sector; the size of the first data is equal to the remaining storage space, and the second data is the remaining data in the target data except the first data.

8. A data storage device, characterized in that: The device comprises: A remaining space determination module, used to determine the remaining storage space of the data area of ​​the sector according to the index information stored in the index area of ​​the sector when writing target data to any sector of the memory; the index information is used to characterize the data writing status of the data area; A storage address determination module, configured to determine a storage address of the target data in the data area according to the index information when the remaining storage space is greater than or equal to the data length of the target data; A data writing module, used for writing the target data into the data area according to the storage address; The index information updating module is used to update the index information stored in the index area according to the data length of the target data.

9. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the data storage method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data storage method according to any one of claims 1 to 7 are implemented.