Data writing method, computer device and storage medium

By adopting cyclic storage method and buffer management in the data storage area, the data abnormalities and life reduction problems caused by frequent erasing of flash memory are solved, and higher memory life and data continuity are achieved.

CN118689409BActive Publication Date: 2024-12-17ZHEJIANG CHINT IOT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411175643.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-26
Publication Date
2024-12-17
Estimated Expiration
2044-08-26

AI Technical Summary

Technical Problem

The existing flash memory-based storage solution has problems such as data exceptions and memory life reduction due to erasing.

Method used

By cyclic storage, the buffer and write area are set in the data storage area to ensure that the buffer is always in the next erase interval of the erase interval of the last written erase interval, thereby avoiding frequent erases and improving memory. lifespan and maintain data continuity.

Benefits of technology

Through cyclic storage, each bit is cycled only once in the memory area, which improves the service life of the memory and ensures that there is always continuous data readable in the data storage area to avoid data exceptions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689409B_ABST
    Figure CN118689409B_ABST
Patent Text Reader

Abstract

The present invention provides a data writing method, a data reading method, a data searching method, a computer device and a storage medium. The data writing method is used to write the data to be written into the data storage area of ​​the memory in a circular storage manner, and the data storage area includes a buffer zone and a data writing area; the method includes: obtaining the data to be written; determining the next erasing interval of the erasing interval where the written data is located last time as the buffer zone, erasing the buffer zone; determining the next writing interval of the writing interval where the written data is located as the data writing area, and writing the data to be written into the data writing area. The data storage area is circulated once, and each bit will be written only once, thereby improving the service life of the memory; setting the buffer zone and making the buffer zone always in the next erasing interval of the erasing interval where the written data is located last time can ensure that there is always a certain size of continuous data readable in the data storage area, avoiding data abnormalities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data management, and in particular to a data writing method, a data reading method, a data searching method, a computer device and a storage medium. Background Art

[0002] In many application scenarios, flash memory is usually used for data storage. Flash memory is erased and written according to sectors, and needs to be erased before each write.

[0003] However, existing storage solutions based on flash memory are prone to data anomalies or reduced memory life due to erasure. Summary of the invention

[0004] In view of the deficiencies in the prior art, the present invention provides a data writing method, a data reading method, a data searching method, a computer device and a storage medium.

[0005] In a first aspect, in one embodiment, the present invention provides a data writing method, the data writing method is used to write the data to be written into the data storage area of ​​the memory in a circular storage manner, the data storage area includes a buffer area and a data writing area; the data writing method includes:

[0006] Get the data to be written;

[0007] Determine the next erasing interval of the erasing interval where the last written data is located as a buffer zone, and erase the data in the buffer zone;

[0008] The next writing interval of the writing interval where the written data is located is determined as the data writing area, and the data to be written is written into the data writing area.

[0009] In one embodiment, before the step of determining the next erase interval of the erase interval where the last written data is located as the buffer area, the data writing method further includes:

[0010] Determine the minimum erasing unit of the data storage area;

[0011] The size of the erase interval is determined based on the minimum erase unit.

[0012] In one embodiment, after the step of writing the data to be written into the data writing area, the data writing method further comprises:

[0013] Determine the storage address corresponding to the data writing area as the latest storage address;

[0014] Write the latest storage address into the data management area of ​​the memory.

[0015] In a second aspect, in one embodiment, the present invention provides a data reading method, the data reading method is used to read the data written by the data writing method in one of the above embodiments; the data reading method comprises:

[0016] Obtaining the target relative position of the data to be read in the data storage area;

[0017] Determine a first target address of the data to be read according to the target relative position and the latest storage address;

[0018] The data to be read is read according to the first target address.

[0019] In one embodiment, the data management area also writes the maximum number of stored data items corresponding to the size of the data storage area and the number of readable stored data items corresponding to the size of the area of ​​the data storage area other than the buffer zone; determining the first target address of the data to be read according to the target relative position includes:

[0020] According to the latest storage address, the maximum number of stored data items and the number of readable stored data items, the earliest storage address is obtained;

[0021] According to the target relative position, a first offset position between the data to be read and the earliest stored data is obtained; the earliest stored data corresponds to the earliest stored address;

[0022] A first target address is obtained according to the earliest storage address and the first offset position.

[0023] In one embodiment, the earliest storage address is obtained according to the latest storage address, the maximum number of stored data items, and the number of readable stored data items, including:

[0024] According to the latest storage address, the maximum number of stored data items and the number of readable stored data items, and based on the following formula, the earliest storage address is obtained;

[0025] earlyaddr=(curPoint+maxEntry–readableEntry)%maxEntry;

[0026] Among them, earlyaddr represents the earliest storage address, curPoint represents the latest storage address, maxEntry represents the maximum number of stored data items, readableEntry represents the number of readable stored data items, and % represents the remainder of the value.

[0027] In one embodiment, determining a first target address of data to be read according to a target relative position includes:

[0028] According to the target relative position, a second offset position between the data to be read and the latest stored data is obtained; the latest stored data corresponds to the latest stored address;

[0029] A first target address is obtained according to the latest storage address and the second offset position.

[0030] In a third aspect, in one embodiment, the present invention provides a data search method, the data search method is used to search for data written by the data writing method in one of the above embodiments, the data in the data storage area is in an increasing trend or a decreasing trend according to the writing time; the data search method comprises:

[0031] Determine the middle address according to the middle relative position and the latest storage address in the data storage area;

[0032] According to the middle address, read and obtain the middle data;

[0033] Compare the middle data with the data to be searched to obtain the comparison result;

[0034] If the comparison result indicates that the middle data is inconsistent with the data to be searched, a new middle relative position is determined in the upper position interval or the lower position interval of the middle relative position, and the above steps are re-executed until the comparison result indicates that the obtained middle data is consistent with the data to be searched, and the middle address obtained last time is determined as the second target address of the data to be searched.

[0035] In a fourth aspect, in one embodiment, the present invention provides a computer device comprising a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the steps in the data writing method in any of the above embodiments, the steps in the data reading method in any of the above embodiments, or the steps in the data searching method in one of the above embodiments.

[0036] In a fifth aspect, in one embodiment, the present invention provides a storage medium storing a computer program, which is loaded by a processor to execute the steps of the data writing method in any of the above embodiments, the steps of the data reading method in any of the above embodiments, or the steps of the data searching method in one of the above embodiments.

[0037] Through the above-mentioned data writing method, data reading method, data searching method, computer equipment and storage medium, storage is performed in a circular storage manner. After the entire data storage area is circulated once, each bit will only be written once, thereby improving the service life of the memory; in addition, a buffer is set, and the buffer is always in the next erase interval of the erase interval where the last written data is located, thereby ensuring that there is always a certain size of continuous data available for reading in the data storage area, avoiding data anomalies. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0039] Figure 1 A schematic diagram of an application scenario of a data writing method in one embodiment of the present invention;

[0040] Figure 2 A schematic diagram of a memory partition in one embodiment of the present invention;

[0041] Figure 3 A schematic diagram of partitioning of a data storage area in one embodiment of the present invention;

[0042] Figure 4 A schematic diagram of a flow chart of a data writing method in one embodiment of the present invention;

[0043] Figure 5 It is a schematic diagram of a data storage area when the storage is not flipped in one embodiment of the present invention;

[0044] Figure 6 A schematic diagram of a data storage area during storage flipping in one embodiment of the present invention;

[0045] Figure 7 A schematic diagram of a data storage area being divided into two parts in one embodiment of the present invention;

[0046] Figure 8 It is a structural schematic diagram of a data writing device in one embodiment of the present invention;

[0047] Fig. 9 The figure is a schematic diagram of the internal structure of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION

[0048] The following will be combined with the 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. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0049] In the description of the present invention, it should be understood that the terms "first" and "second" are used only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined. In the present application, the word "exemplary" is used to mean "used as an example, illustration or description". Any embodiment described as "exemplary" in the present application is not necessarily interpreted as being more preferred or more advantageous than other embodiments. In order to enable any person skilled in the art to implement and use the present invention, the following description is given. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present invention can be implemented without using these specific details. In other examples, well-known structures and processes will not be elaborated in detail to avoid unnecessary details that make the description of the present invention obscure. Therefore, the present invention is not intended to be limited to the embodiments shown, but is consistent with the widest range of principles and features disclosed in the present application.

[0050] The data writing method in the embodiment of the present invention is applied to a data writing device, and the data writing device is arranged in a computer device; the computer device can be a terminal, such as a mobile phone or a tablet computer, and the computer device can also be a server, or a service cluster composed of multiple servers.

[0051] like Figure 1 As shown, Figure 1 Schematic diagram of an application scenario of the data writing method in an embodiment of the present invention. The application scenario of the data writing method in an embodiment of the present invention includes a computer device 100 (a data writing device is integrated in the computer device 100), and a computer-readable storage medium corresponding to the data writing method is run in the computer device 100 to execute the steps of the data writing method.

[0052] Understandably, Figure 1 The computer device in the application scenario of the data writing method shown, or the device included in the computer device, does not constitute a limitation on the embodiments of the present invention, that is, the number of devices and types of devices included in the application scenario of the data writing method, or the number of devices and types of devices included in each device, do not affect the overall implementation of the technical solution in the embodiments of the present invention, and can all be regarded as equivalent replacements or derivatives of the technical solution claimed to be protected in the embodiments of the present invention.

[0053] The computer device 100 in the embodiment of the present invention may be an independent device, or a device network or device cluster composed of devices. For example, the computer device 100 described in the embodiment of the present invention includes but is not limited to a computer, a network host, a single network device, a plurality of network devices, or a cloud device composed of a plurality of devices. The cloud device is composed of a large number of computers or network devices based on cloud computing.

[0054] Those skilled in the art will understand that Figure 1 The application scenario shown in the figure is only an application scenario corresponding to the technical solution of the present invention, and does not constitute a limitation on the application scenario of the technical solution of the present invention. Other application scenarios may also include Figure 1 More or fewer computer devices shown in, or computer device network connection relationships, such as Figure 1 Only one computer device is shown. It can be understood that the scenario of the data writing method can also include one or more other computer devices, which are not specifically limited here. The computer device 100 can also include a memory for storing information related to the data writing method.

[0055] In addition, in the application scenario of the data writing method in the embodiment of the present invention, the computer device 100 may be provided with a display device, or the computer device 100 may not be provided with a display device and may be in communication connection with an external display device 200, and the display device 200 is used to output the result of the execution of the data writing method in the computer device. The computer device 100 may access a backend database 300 (the backend database 300 may be a local memory of the computer device 100, or the backend database 300 may also be provided in the cloud), and the backend database 300 stores information related to the data writing method.

[0056] It should be noted that Figure 1 The application scenario of the data writing method shown is only an example. The application scenario of the data writing method described in the embodiment of the present invention is to more clearly illustrate the technical solution of the embodiment of the present invention, and does not constitute a limitation on the technical solution provided by the embodiment of the present invention.

[0057] Based on the application scenario of the above data writing method, an embodiment of the data writing method is proposed.

[0058] In a first aspect, in one embodiment, the present invention provides a data writing method, the data writing method is used to write data to be written into a data storage area of ​​a memory in a cyclic storage manner.

[0059] Among them, Figure 2 As shown, the memory includes a data management area in addition to a data storage area. Figure 3As shown, the data storage area includes a buffer area and a data writing area. The buffer area is used for data erasing, and the data writing area is used for data writing. Figure 3 Data record 1, data record 2, data record 3, ..., data record 8, etc. written in.

[0060] like Figure 4 As shown, the data writing method includes:

[0061] Step 201, obtaining data to be written.

[0062] The data to be written may be meter data. The meter data may include electric energy measurement data, such as current power consumption, including integer part, decimal part and pulse part. The meter data may also include power conditions, including combined active power, forward active power and reverse active power.

[0063] Step 202: determine the next erasing interval of the erasing interval where the last written data is located as a buffer area, and erase the data in the buffer area.

[0064] The size corresponding to an erase interval can support the writing of one or more data, that is, the written data written multiple times in succession may be located in the same erase interval, so that the multiple erase operations corresponding to the multiple consecutive write operations also target the same erase interval.

[0065] Specifically, in a flash memory, the size of an erase interval can be a sector. Taking a 32M flash memory as an example, the size of a sector is 4096 bytes. Taking the meter data as an example, the size of the corresponding written data is usually only a few dozen bytes, that is, a sector can support the writing of a few dozen data. For example, when writing the first data to the first sector, the second sector is erased first. Since a sector can support writing multiple data, the second data is still written to the first sector. When writing the second data to the first sector, the second sector is still erased first. And so on, until the first sector is full and the second sector is written. When writing the second sector, the third sector is erased first.

[0066] Step 203: determine the next writing interval of the writing interval where the written data is located as the data writing area, and write the data to be written into the data writing area.

[0067] The data writing area represents the real-time area for writing data, and its size is consistent with the writing interval. Figure 3In the example, when writing data record 1, the writing interval where data record 1 is located is used as the data writing area, and then when writing data record 2, the writing interval where data record 2 is located is used as the data writing area. That is to say, the data writing area changes in real time and only represents the writing interval when writing data.

[0068] Each write interval is used to write one data, and the above steps have mentioned that the size corresponding to an erase interval can support the writing of one or more data, that is, the size corresponding to an erase interval can include the size of one or more write intervals.

[0069] When storing based on ROM memory, since ROM memory is directly written in bytes and does not require erasure before writing, in this embodiment, the buffer corresponding to the ROM memory can be set to 0. It should be noted that due to the circular storage method, when the data written in the ROM memory reaches its storage upper limit, writing again will overwrite the first data. In this case, the buffer can be understood as a writing interval.

[0070] The ROM memory may be an EEPROM memory.

[0071] In summary, the data writing method in this embodiment can solve the related drawbacks of the existing flash memory and is also compatible with ROM memory.

[0072] Through the above data writing method, the data is stored in a circular storage manner. After the entire data storage area is circulated once, each bit will only be written once, thereby improving the service life of the memory; in addition, a buffer is set, and the buffer is always in the next erase interval of the erase interval where the last written data is located, so as to ensure that there is always a certain size of continuous data readable in the data storage area, avoiding data anomalies.

[0073] In one embodiment, before the step of determining the next erase interval of the erase interval where the last written data is located as the buffer area, the data writing method further includes:

[0074] Determines the minimum erase unit of the data storage area.

[0075] Among them, the minimum erasing unit of different memories is different. Taking flash memory as an example, the minimum erasing unit is a sector; taking ROM memory as an example, only after the storage reaches the upper limit boundary, the data written again will overwrite the first data, that is, the first data will be erased. The corresponding minimum erasing unit can be understood as a write interval, taking the meter data as an example, it is dozens of bytes.

[0076] The size of the erase interval is determined based on the minimum erase unit.

[0077] The erase interval is used to determine the buffer zone of the real-time change position, and the buffer zone is mainly used to implement the erase operation of the flash memory and other memories that need to be erased before writing. The smaller the erase interval is set, the smaller the corresponding buffer zone is, so that the area in the data storage area other than the buffer zone is larger, and the amount of data that can be effectively stored is larger.

[0078] In one embodiment, after the step of writing the data to be written into the data writing area, the data writing method further comprises:

[0079] The storage address corresponding to the data writing area is determined as the latest storage address.

[0080] The data is usually written in the form of a record pointer. When writing for the first time, the record pointer corresponds to the base address. Each time writing is done, the record pointer increases by one, that is, the corresponding address recorded is the latest storage address.

[0081] Write the latest storage address into the data management area of ​​the memory.

[0082] The data written in the data storage area needs to be read or searched later, although the data written in the data storage area is stored in a circular manner, that is, it has continuity. However, reading or searching at least requires knowing the latest storage address currently written, so that it can be realized based on the latest storage address and the relevant information of the data to be read or searched.

[0083] In addition to the latest storage address, the data management area can also write other related index data that helps read or search, such as the maximum number of storage data items corresponding to the size of the data storage area and the number of readable storage data items corresponding to the size of the area of ​​the data storage area excluding the buffer zone.

[0084] In one embodiment, since the buffer changes in real time and is always located in the next erase interval of the erase interval where the last written data is located, when the storage upper limit boundary is reached, the buffer may move to the erase interval where the data written first is located, resulting in the data in the erase interval being erased.

[0085] Among them, Figure 5As shown, the size of the erase interval corresponds to the size of the three write intervals, that is, the size of the buffer corresponds to three data records. When data record 12 needs to be written, the next erase interval (such as the area where unrecorded data record 12, data record 13 and data record 14 are located) of the erase interval where data record 11 is located (such as the area where recorded data record 11 and unrecorded data record 12 and data record 13 are located) is first determined as the buffer. Since the data storage area can store a maximum of 13 data records, the unrecorded data record 14 mentioned above should correspond to the area where the originally recorded data record 1 is located. Figure 5 Although the buffer in the memory is moved to the erase interval where the data written at the beginning is located, the offset position is relatively small, so that there is still a continuous set of data records in the data storage area that remain as a whole in terms of the storage address, such as data record 2 to data record 11, there are a total of 10 data records. For example, the address of data record 1 written at the beginning is 0, the address of data record 2 is 1, the address of data record 3 is 2, ..., the address of data record 11 is 10, that is, the addresses corresponding to the 10 data records are also continuous 1 to 10.

[0086] When the offset position of the buffer is relatively large, the buffer may make the addresses corresponding to the continuously written data records discontinuous. Figure 6 As shown, the buffer currently corresponds to the area where the originally recorded data records 3, data record 4 and data record 5 are located, which causes the continuously written data records 6 to data record 15 to be divided into two parts, the upper and lower parts. The addresses corresponding to the data records 6 to data record 13 in the upper part are continuous 5 to 12, and the addresses corresponding to the data records 14 to data record 15 in the lower part are continuous 0 to 1. Although the addresses of the upper and lower parts are continuous, they are not continuous as a whole. This application defines this situation as storage flipping.

[0087] It should be noted that, whether Figure 5 The storage is not flipped or Figure 6 Storage flipping can ensure that at least 10 consecutive data records in the data storage area can be read or searched, that is, no matter how the referenced buffer changes, it will not cause data anomalies.

[0088] In a second aspect, in one embodiment, the present invention provides a data reading method, the data reading method is used to read the data written by the data writing method in one of the above embodiments; the data reading method comprises:

[0089] Get the target relative position of the data to be read in the data storage area.

[0090] Among them, the above embodiments have mentioned that the data storage area always stores multiple continuous data from the oldest to the newest, so the target relative position represents the position of the data to be read in the multiple continuous data. For example, the target relative position can be "the second data", which refers to the second data from the oldest to the newest in the multiple continuous data.

[0091] A first target address of the data to be read is determined according to the target relative position and the latest storage address.

[0092] Among them, the latest storage address corresponds to the latest storage data, and the target relative position can reflect the offset between the latest storage data and the data to be read, so that based on the offset and the latest storage address, the first target address corresponding to the read data can be determined, and the first target address is one of the physical addresses in the data storage area that continuously increases from the base address.

[0093] The data to be read is read according to the first target address.

[0094] After obtaining the first target address, the area of ​​the data to be read can be located based on the first target address, so that the data can be directly read.

[0095] In one embodiment, the data management area also writes the maximum number of stored data items corresponding to the size of the data storage area and the number of readable stored data items corresponding to the size of the area of ​​the data storage area other than the buffer zone; determining the first target address of the data to be read according to the target relative position includes:

[0096] The earliest storage address is obtained according to the latest storage address, the maximum number of stored data items and the number of readable stored data items.

[0097] Among them, according to the latest storage address, the maximum number of stored data items and the number of readable stored data items, and based on the following formula, the earliest storage address is obtained;

[0098] earlyaddr=(curPoint+maxEntry–readableEntry)%maxEntry;

[0099] Among them, earlyaddr represents the earliest storage address, curPoint represents the latest storage address, maxEntry represents the maximum number of stored data items, readableEntry represents the number of readable stored data items, and % represents the remainder of the value.

[0100] Among them, Figure 6 As shown, curPoint is 2, maxEntry is 13, and readableEntry is 10, then earlyaddr can be obtained as (2+13-10)%13=5, that is, Figure 6 Data record 6 in.

[0101] According to the target relative position, the first offset position between the data to be read and the earliest stored data is obtained; the earliest stored data corresponds to the earliest stored address.

[0102] Among them, the above-mentioned embodiment has mentioned that the target relative position represents the position of the data to be read in the multiple continuous data, and the position of the earliest stored data in the multiple continuous data is known, so that the first offset position between the earliest stored data and the data to be read can be determined according to the target relative position, and the first offset position represents the position difference between the position of the data to be read in the multiple continuous data and the position of the earliest stored data in the multiple continuous data.

[0103] A first target address is obtained according to the earliest storage address and the first offset position.

[0104] In general, the order difference between data and the order difference between addresses are the same, so after obtaining the first offset position, the first target address can be obtained according to the earliest storage address.

[0105] Among them, Figure 6 As shown, if the second data record needs to be read, the bit difference between the second data record and the earliest data record (which can also be understood as the first data record) is 1, so the first target address can be obtained as 5+1=6, that is, Figure 6 Data record 7 in.

[0106] In one embodiment, determining a first target address of data to be read according to a target relative position includes:

[0107] According to the target relative position, a second offset position between the data to be read and the latest stored data is obtained; the latest stored data corresponds to the latest stored address.

[0108] Among them, the above embodiment has mentioned that the determination of the first target address of the data to be read can be realized based on the earliest stored data and the earliest stored address, which is essentially based on the association between continuous data. Therefore, in this embodiment, the determination of the first target address of the data to be read can also be realized directly based on the latest stored data and the latest stored address. The difference is that in this embodiment, the second offset position between the data to be read and the latest stored data needs to be determined, which has the same function as the above-mentioned first offset position and will not be repeated here.

[0109] A first target address is obtained according to the latest storage address and the second offset position.

[0110] Among them, Figure 6As shown, the latest storage address is the address of data record 15, that is, 1. If the second data record needs to be obtained, since the number of readable storage data records is 10, the latest data record can be understood as the tenth data record. The difference in rank between the second data record and the latest data record is 8. By shifting 8 rank forward from the latest data record, data record 7 can be determined.

[0111] In one embodiment, in order to make the above data reading method clearer, the above embodiments are now described in combination. Figure 6 As shown, if the second data record needs to be read, the first target address determined is (curPoint+maxEntry–readableEntry)%maxEntry+2-1=(2+13-10)%13+2-1=6.

[0112] Among them, "+2" represents the position of the second data record; since the address increases from 0 and the position increases directly from 1, "-1" is used to correct the deviation between the address and the position.

[0113] It should be noted that the above formula is only used when both the data to be read and the earliest stored data are located in one of the two parts into which the buffer is divided. Figure 6 As shown in the figure, if the ninth data record needs to be read, the first target address that can be determined according to the above formula is (curPoint+maxEntry–readableEntry)%maxEntry+9-1=(2+13-10)%13+9-1=13. However, the maximum number of data records that can be stored in the data storage area is 13, and the corresponding address range is 0 to 12. The first target address of 13 cannot be located in the data storage area. Therefore, for this situation, the result needs to be modulo, that is, ((2+13-10)%13+9-1)%13=0, that is, Figure 6 Data record 14 in.

[0114] In summary, in order to meet various reading requirements, the optimized formula is ((curPoint+maxEntry–readableEntry)%maxEntry+position-1)%maxEntry.

[0115] In a third aspect, in one embodiment, the present invention provides a data search method, which is used to search for data written by the data writing method in one of the above embodiments, and the data in the data storage area shows an increasing trend or a decreasing trend according to the writing time.

[0116] When the data is electric energy metering data, it actually records the accumulated amount of electric power, which is incremental data, that is, each written electric energy metering data increases compared with the last written electric energy metering data.

[0117] Among them, the data search method is mainly used for how to locate in the data storage area when the value of the data is known, so as to determine the writing time of the data, the amount of change before and after, etc. When the amount of data written in the data storage area is small, each piece of data can be read in turn, and then compared in turn, so as to determine the data to be searched. However, when the amount of data is large, the method of comparing in turn will consume a lot of time and be very inefficient. Therefore, in view of this situation, this embodiment adopts a binary method to achieve the purpose of data search when the amount of data is large.

[0118] Specifically, the data search method includes:

[0119] The middle address is determined based on the middle relative position in the data storage area and the latest storage address.

[0120] Among them, Figure 7 As shown, the earliest data record is used as the left boundary of the binary division, and the latest data record is used as the right boundary of the binary division. The number of data records between the left boundary and the right boundary is 10, that is, the number of readable and stored data. The middle relative position can refer to the fifth or sixth of the 10 consecutive data. Taking the fifth data record as an example, using the address formula in the above embodiment, the middle address corresponding to the fifth data record can be determined as ((curPoint+maxEntry–readableEntry)%maxEntry+position-1)%maxEntry=((2+13-10)%13+5-1)%13=9.

[0121] According to the middle address, read and obtain the middle data;

[0122] Among them, continuing the example of the above steps, if the determined middle address is 9, the corresponding middle data is Figure 6 Data record 10 in.

[0123] Compare the middle data with the data to be searched to obtain the comparison result;

[0124] The comparison result includes a comparison result indicating that the middle data is consistent with the data to be found, a comparison result indicating that the middle data is greater than the data to be found, or a comparison result indicating that the middle data is less than the data to be found.

[0125] If the comparison result indicates that the middle data is inconsistent with the data to be searched, a new middle relative position is determined in the upper position interval or the lower position interval of the middle relative position, and the above steps are re-executed until the comparison result indicates that the obtained middle data is consistent with the data to be searched, and the middle address obtained last time is determined as the second target address of the data to be searched.

[0126] If the comparison result indicates that the middle data is inconsistent with the data to be found, a search is required. Specifically, taking the example of the above steps, if the fifth data record is smaller than the data record to be found, it means that the data record to be found is located between the sixth data record and the tenth data record, so the re-determined middle relative position can be the position of the eighth data record.

[0127] Fourthly, Figure 8 As shown, in one embodiment, the present invention provides a data writing device, which is used to write the data to be written into the data storage area of ​​the memory in a circular storage manner, and the data storage area includes a buffer area and a data writing area; the data writing device includes:

[0128] The data acquisition module 301 is used to acquire the data to be written;

[0129] The data erasing module 302 is used to determine the next erasing interval of the erasing interval where the last written data is located as a buffer zone, and to erase the data in the buffer zone;

[0130] The data writing module 303 is used to determine the next writing interval of the writing interval where the written data is located as the data writing area, and write the data to be written into the data writing area.

[0131] Through the above-mentioned data writing device, storage is performed in a circular storage manner. After the entire data storage area is circulated once, each bit will only be written once, thereby improving the service life of the memory; in addition, a buffer is set, and the buffer is always in the next erase interval of the erase interval where the last written data is located, thereby ensuring that there is always a certain size of continuous data available for reading in the data storage area, avoiding data anomalies.

[0132] In one embodiment, the data writing device further includes:

[0133] The size determination module is used to determine the minimum erasure unit of the data storage area before determining the next erasure interval of the erasure interval where the last written data is located as the buffer zone; and determine the size of the erasure interval according to the minimum erasure unit.

[0134] In one embodiment, the data writing device further includes:

[0135] The data management module is used to determine the storage address corresponding to the data writing area as the latest storage address after the step of writing the data to be written into the data writing area; and write the latest storage address into the data management area of ​​the memory.

[0136] In a fifth aspect, in one embodiment, the present invention provides a computer device, such as Fig. 9 As shown, it shows the structure of the computer device involved in the present invention, specifically:

[0137] The computer device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that Fig. 9 The structure of the computer device shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:

[0138] The processor 401 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 402 and calling data stored in the memory 402, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and computer programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.

[0139] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the server, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0140] The computer device also includes a power supply 403 for supplying power to various components. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0141] The computer device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0142] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically, in this embodiment, when the computer device is a model training computer device, the processor 401 in the computer device will load the executable files corresponding to the processes of one or more computer programs into the memory 402 according to the following instructions, and the processor 401 will run the computer program stored in the memory 402 to perform the following steps:

[0143] Get the data to be written;

[0144] Determine the next erasing interval of the erasing interval where the last written data is located as a buffer zone, and erase the data in the buffer zone;

[0145] The next writing interval of the writing interval where the written data is located is determined as the data writing area, and the data to be written is written into the data writing area.

[0146] Through the above-mentioned computer device, storage is performed in a circular storage manner. After the entire data storage area is circulated once, each bit will only be written once, thereby increasing the service life of the memory. In addition, a buffer is set, and the buffer is always in the next erase interval of the erase interval where the last written data is located, thereby ensuring that there is always a certain size of continuous data available for reading in the data storage area, avoiding data anomalies.

[0147] A person of ordinary skill in the art will appreciate that all or part of the steps in any of the methods of the above embodiments may be completed by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0148] In a sixth aspect, in one embodiment, the present invention provides a storage medium, wherein a plurality of computer programs are stored, and the computer programs can be loaded by a processor to perform the following steps:

[0149] Get the data to be written;

[0150] Determine the next erasing interval of the erasing interval where the last written data is located as a buffer zone, and erase the data in the buffer zone;

[0151] The next writing interval of the writing interval where the written data is located is determined as the data writing area, and the data to be written is written into the data writing area.

[0152] By using the above storage medium, storage is performed in a circular storage manner. After the entire data storage area is circulated once, each bit will only be written once, thereby increasing the service life of the memory. In addition, a buffer is set, and the buffer is always in the next erase interval of the erase interval where the last written data is located, thereby ensuring that a certain size of continuous data is always readable in the data storage area, avoiding data anomalies.

[0153] It will be appreciated by those skilled in the art that any reference to memory, storage, database or other medium used in the embodiments provided by the present invention may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink), DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0154] Since the computer program stored in the storage medium can execute the steps in the data writing method in any embodiment provided by the present invention, the beneficial effects that can be achieved by the data writing method in any embodiment provided by the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0155] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0156] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.

[0157] The above is a detailed introduction to a data writing method, device, data reading method, data searching method, computer equipment and storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

[0158] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

Claims

1. A data writing method, characterized in that: The data writing method is used to write the data to be written into the data storage area of ​​the memory in a circular storage manner, wherein the data storage area includes a buffer area and a data writing area; the data writing method includes: Acquire the data to be written; Determine the next erasing interval of the erasing interval where the last written data is located as the buffer area, and erase the data in the buffer area; Determine the next writing interval of the writing interval where the written data is located as the data writing area, and write the data to be written into the data writing area; Before the step of determining the next erase interval of the erase interval where the last written data is located as the buffer area, the data writing method further includes: Determine the minimum erasure unit of the data storage area; Determining the size of the erasure interval according to the minimum erasure unit; After the step of writing the data to be written into the data writing area, the data writing method further comprises: Determine the storage address corresponding to the data writing area as the latest storage address; Writing the latest storage address into the data management area of ​​the memory; The data written by the data writing method is searched by a data searching method, and the data in the data storage area shows an increasing trend or a decreasing trend according to the writing time; the data searching method includes: Determine the middle address according to the middle relative position in the data storage area and the latest storage address; According to the middle address, read and obtain the middle data; Compare the middle data with the data to be searched to obtain a comparison result; If the comparison result indicates that the middle data is inconsistent with the data to be searched, a new middle relative position is determined in the upper position interval or the lower position interval of the middle relative position, and the above steps are re-executed until the comparison result indicates that the obtained middle data is consistent with the data to be searched, and the middle address obtained last time is determined as the second target address of the data to be searched.

2. A data reading method, characterized in that: The data reading method is used to read the data written by the data writing method according to claim 1; the data reading method comprises: Obtaining a target relative position of the data to be read in the data storage area; Determining a first target address of the data to be read according to the target relative position and the latest storage address; The data to be read is read according to the first target address.

3. The data reading method according to claim 2, characterized in that: The data management area also stores a maximum number of stored data corresponding to the size of the data storage area and a number of readable stored data corresponding to the size of the area of ​​the data storage area excluding the buffer zone; and determining the first target address of the data to be read according to the target relative position includes: Obtaining the earliest storage address according to the latest storage address, the maximum number of stored data items, and the number of readable stored data items; According to the target relative position, a first offset position between the data to be read and the earliest stored data is obtained; the earliest stored data corresponds to the earliest stored address; The first target address is obtained according to the earliest storage address and the first offset position.

4. The data reading method according to claim 3, characterized in that: The obtaining the earliest storage address according to the latest storage address, the maximum number of stored data items, and the number of readable stored data items comprises: According to the latest storage address, the maximum number of stored data items and the number of readable stored data items, and based on the following formula, the earliest storage address is obtained; earlyaddr=(curPoint+maxEntry–readableEntry)%maxEntry; Among them, earlyaddr represents the earliest storage address, curPoint represents the latest storage address, maxEntry represents the maximum number of stored data items, readableEntry represents the number of readable stored data items, and % represents the remainder of the value.

5. The data reading method according to claim 2, characterized in that: Determining the first target address of the data to be read according to the target relative position includes: According to the target relative position, a second offset position between the data to be read and the latest stored data is obtained; the latest stored data corresponds to the latest stored address; The first target address is obtained according to the latest storage address and the second offset position.

6. A computer device, characterized in that: It comprises a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the steps in the data writing method according to claim 1 or the steps in the data reading method according to any one of claims 2 to 5.

7. A storage medium, characterized in that: The storage medium stores a computer program, and the computer program is loaded by a processor to execute the steps in the data writing method of claim 1 or the steps in the data reading method of any one of claims 2 to 5.