Data processing method, electronic device and storage medium
By dividing the index area and data area in the memory of the smart device and performing data block operations, the problems of low memory write operation efficiency and short service life are solved, and more efficient data writing and longer storage life are achieved.
Patent Information
- Application Number
- CN201910968888.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-10-12
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2039-10-12
AI Technical Summary
In the memory of smart devices, the writing operation efficiency is low and the number of erasing and writing is limited, resulting in a shortened memory service life.
By dividing the storage space into an index area and a data area, and performing block operations according to the number of rows of data to be written, the number of erasing and writing of the storage space is reduced, writing efficiency is improved, and service life is extended.
It improves the efficiency of data writing in the storage space, extends the service life of the storage space, and reduces the wear and tear on the memory.
Smart Images

Figure CN111221470B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a data processing method, an electronic device and a storage medium. Background Art
[0002] At present, when using smart devices such as mobile phones and computers, the memory of the device needs to perform data read and write operations. When the memory is writing, no matter how much data is written, the memory needs to perform large-scale erase or write operations, resulting in low efficiency of data writing. In addition, due to the design of the memory itself, the number of erase and write times of the memory is limited. A large number of write operations will reduce the service life of the memory. Summary of the invention
[0003] In view of the above, the present invention provides a data processing method, an electronic device and a storage medium, which aims to improve the efficiency of writing data into the storage space and extend the service life of the storage space.
[0004] To achieve the above object, the present invention provides a data processing method, which comprises:
[0005] Initialization step: dividing a preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, dividing the first data area into a second index area and a second data area according to a second preset ratio, and obtaining an initial total number of rows of the storage space and an initial minimum number of rows per block of the storage space;
[0006] Receiving step: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written;
[0007] Block division step: comparing the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculating the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result; and
[0008] Writing steps: based on the number of data blocks and the number of row data of each data block, write each data block of the data to be written into the first data area, write the row data of each data block of the data to be written into the second data area, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area.
[0009] In one embodiment, the method further comprises the step of reading:
[0010] receiving a data reading request sent by the user, wherein the data reading request includes index information of the data to be read in the storage space;
[0011] According to the index information, obtaining the identification position of the data to be read in the second index area in the storage space;
[0012] According to the identification position of the second index area, the identification position of the data to be read in the second data area in the storage space is obtained, and the data is read according to the identification position of the second data area.
[0013] In one embodiment, the block division step specifically includes:
[0014] When the total number of rows of the data to be written is greater than or equal to the initial total number of rows of the storage space, a first calculation rule is used to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block;
[0015] When the total number of rows of the data to be written is less than the initial total number of rows of the storage space, the second calculation rule is used to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block.
[0016] In one embodiment, the first calculation rule includes: the number of data blocks corresponding to the data to be written = the total number of rows of the data to be written / (the minimum number of rows per block in the initial storage space × a), where a is a positive integer greater than 1;
[0017] The second calculation rule includes: the number of data blocks corresponding to the data to be written = (the total number of rows of the data to be written + the initial minimum number of rows per block of the storage space) / the initial minimum number of rows per block of the storage space.
[0018] In one embodiment, the step of dividing the blocks further includes:
[0019] Calculate the first index area memory space corresponding to the data to be written according to the number of the data blocks and the storage bytes of the index information of each data block, and determine the identification position of the first data area according to the first index area memory space;
[0020] According to the number of row data and the index information storage bytes of each row data, a second index area memory space corresponding to the data to be written is calculated, and an identification position of the second data area is determined according to the second index area memory space.
[0021] To achieve the above object, the present invention further provides an electronic device, comprising: a memory and a processor, wherein the memory stores a data processing program, and the data processing program is executed by the processor to implement the following steps:
[0022] Initialization step: dividing a preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, dividing the first data area into a second index area and a second data area according to a second preset ratio, and obtaining an initial total number of rows of the storage space and an initial minimum number of rows per block of the storage space;
[0023] Receiving step: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written;
[0024] Block division step: comparing the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculating the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result; and
[0025] Writing steps: based on the number of data blocks and the number of row data of each data block, write each data block of the data to be written into the first data area, write the row data of each data block of the data to be written into the second data area, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area.
[0026] In one embodiment, the data processing program is executed by the processor and further implements the reading step:
[0027] receiving a data reading request sent by the user, wherein the data reading request includes index information of the data to be read in the storage space;
[0028] According to the index information, obtaining the identification position of the data to be read in the second index area in the storage space;
[0029] According to the identification position of the second index area, the identification position of the data to be read in the second data area in the storage space is obtained, and the data is read according to the identification position of the second data area.
[0030] In one embodiment, the block division step specifically includes:
[0031] When the total number of rows of the data to be written is greater than or equal to the initial total number of rows of the storage space, a first calculation rule is used to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block;
[0032] When the total number of rows of the data to be written is less than the initial total number of rows of the storage space, the second calculation rule is used to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block.
[0033] In one embodiment, the block division step further includes:
[0034] Calculate the first index area memory space corresponding to the data to be written according to the number of the data blocks and the storage bytes of the index information of each data block, and determine the identification position of the first data area according to the first index area memory space;
[0035] According to the number of row data and the index information storage bytes of each row data, a second index area memory space corresponding to the data to be written is calculated, and an identification position of the second data area is determined according to the second index area memory space.
[0036] To achieve the above objectives, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a data processing program, and when the data processing program is executed by a processor, any step in the data processing method described above can be implemented.
[0037] The data processing method, electronic device and storage medium proposed in the present invention divide the preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, divide the first data area into a second index area and a second data area according to a second preset ratio, receive a request for writing data issued by a user, compare the total number of rows of data to be written with the initial total number of rows obtained after the storage space is partitioned, calculate the number of data blocks after the data to be written is divided and the number of row data of each data block according to the comparison result, write the row data of each data block of the data to be written into the second data area based on the number of data blocks and the number of row data of each data block, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area. When the storage space is written, only the data blocks of a part of the data area of the storage space are written, which reduces the number of erasures and writes to the storage space, improves the efficiency of data writing in the storage space and prolongs the service life of the storage space. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A schematic diagram of a preferred embodiment of the electronic device of the present invention;
[0039] Figure 2 for Figure 1 A schematic diagram of the modules of a preferred embodiment of the data processing program;
[0040] Figure 3 A flowchart of a preferred embodiment of the data processing method of the present invention;
[0041] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0043] Reference Figure 1 FIG. 2 is a schematic diagram of a preferred embodiment of the electronic device 1 of the present invention.
[0044] The electronic device 1 includes but is not limited to: a memory 11, a processor 12, a display 13 and a network interface 14. The electronic device 1 is connected to a network through the network interface 14 to obtain raw data. The network may be a wireless or wired network such as an intranet, the Internet, a global system of mobile communications (GSM), a wideband code division multiple access (WCDMA), a 4G network, a 5G network, Bluetooth, Wi-Fi, a call network, etc.
[0045] Among them, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of the electronic device 1, such as a hard disk or memory of the electronic device 1. In other embodiments, the memory 11 can also be an external storage device of the electronic device 1, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped with the electronic device 1. Of course, the memory 11 can also include both the internal storage unit of the electronic device 1 and its external storage device. In this embodiment, the memory 11 is generally used to store the operating system and various application software installed in the electronic device 1, such as the program code of the data processing program 10, etc. In addition, the memory 11 can also be used to temporarily store various types of data that have been output or are to be output.
[0046] In some embodiments, the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 12 is generally used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the program code of the data processing program 10.
[0047] The display 13 may be referred to as a display screen or a display unit. In some embodiments, the display 13 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (OLED) touch device. The display 13 is used to display information processed in the electronic device 1 and to display a visual working interface, such as displaying the results of data statistics.
[0048] The network interface 14 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface). The network interface 14 is generally used to establish a communication connection between the electronic device 1 and other electronic devices.
[0049] Figure 2 Only the electronic device 1 having components 11 - 14 and a data processing program 10 is shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0050] Optionally, the electronic device 1 may further include a user interface, which may include a display, an input unit such as a keyboard, and an optional user interface may further include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (OLED) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.
[0051] The electronic device 1 may further include a radio frequency (RF) circuit, a sensor, an audio circuit, etc., which will not be described in detail here.
[0052] In the above embodiment, the processor 12 may implement the following steps when executing the data processing program 10 stored in the memory 11:
[0053] Initialization step: dividing a preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, dividing the first data area into a second index area and a second data area according to a second preset ratio, and obtaining an initial total number of rows of the storage space and an initial minimum number of rows per block of the storage space;
[0054] Receiving step: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written;
[0055] Block division step: comparing the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculating the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result; and
[0056] Writing steps: based on the number of data blocks and the number of row data of each data block, write each data block of the data to be written into the first data area, write the row data of each data block of the data to be written into the second data area, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area.
[0057] The storage device may be the memory 11 of the electronic device 1 , or may be other storage devices that are communicatively connected to the electronic device 1 .
[0058] For a detailed description of the above steps, please refer to the following Figure 2 A program module diagram of an embodiment of the data processing program 10 and Figure 3 Description of a flow chart of an embodiment of a data processing method.
[0059] In other embodiments, the data processing program 10 may be divided into multiple modules, which are stored in the memory 12 and executed by the processor 13 to implement the present invention. The module referred to in the present invention refers to a series of computer program instruction segments that can implement specific functions.
[0060] Reference Figure 2 As shown, Figure 1 FIG. 1 is a program module diagram of an embodiment of a data processing program 10. In this embodiment, the data processing program 10 can be divided into: an initialization module 110, a receiving module 120, a block module 130 and a writing module 140.
[0061] The initialization module 110 is used to divide the preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, divide the first data area into a second index area and a second data area according to a second preset ratio, and obtain the initial total number of rows of the storage space and the initial minimum number of rows per block of the storage space.
[0062] In this embodiment, the preset storage space is a medium required for data storage, such as a flash memory, a hard disk, a multimedia card, a card-type memory, etc. Data is written into the storage space in units of data blocks. The preset storage space of the storage device is divided into a first index area and a first data area according to a first preset ratio (for example, 1:20). The first index area stores the identification positions of the first block, the second block to the Nth block of data blocks in sequence. Each data block in the first data area is divided into a second index area and a second data area according to a second preset ratio (for example, 1:15). The second index area stores the identification positions of the first row, the second row to the Nth row of data of the data block in sequence. The second data area stores the data of the first row, the second row to the Nth row of data of the data block in sequence. According to the data row identification position in the second index area, any row of data can be found in the second data area. If the data block is too large, the efficiency of searching for the row will be reduced; if the data block is too small, the number of data blocks will be too large, which will also reduce the efficiency of searching for the data block. Therefore, the storage space is partitioned reasonably to obtain data blocks of moderate size. The initial total number of rows in the storage space = the maximum number of data blocks after the initial partitioning * the minimum number of rows in each data block after the initial partitioning.
[0063] The first data area is used to store data blocks written into the storage space, the first index area is used to store index information of the data blocks, the second data area is used to store row data of each data block, and the second index area is used to store index information of the row data of each data block.
[0064] The receiving module 120 is configured to receive a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written.
[0065] In this embodiment, the data to be written is taken as report data for example to illustrate this case. The report data writing request issued by the user includes the total number of rows of the report to be written.
[0066] The block division module 130 is used to compare the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result.
[0067] In this embodiment, before writing data into the storage space, it is necessary to perform a block operation on the data to be written, and the data to be written is taken as report data for explanation. If the total number of rows of the data to be written is greater than or equal to the initial total number of rows after the storage space is partitioned, the first calculation rule is used to calculate the number of data blocks after the data to be written is partitioned and the number of rows of each data block; if the total number of rows of the data to be written is less than the initial total number of rows after the storage space is partitioned, the second calculation rule is used to calculate the number of data blocks after the data to be written is partitioned and the number of rows of each data block.
[0068] Specifically, if the total number of rows of data to be written is greater than or equal to the initial total number of rows after the storage space is partitioned, the number of data blocks of data to be written = the total number of rows to be written / (the initial minimum number of rows per block of the storage space*a), where a is a positive integer greater than 1; if the number of rows of data to be written is less than the initial total number of rows, the number of data blocks of data to be written = (the total number of rows of data to be written + the initial minimum number of rows per block of the storage space) / the initial minimum number of rows per block of the storage space.
[0069] For example: the data to be written is 200 rows of report data, the initial total number of rows after the storage space is partitioned is 100, and the initial minimum number of rows in each block of the storage space is 60. Because the total number of rows of data to be written is less than the initial total number of rows after the storage space is partitioned (200<100×60), the second calculation rule is used to calculate the number of data blocks after the report is partitioned and the number of data rows of each data block, that is, the number of data blocks of the report = (200+60) / 60 = 4.3, and the result is integerized to obtain the number of data blocks of the report partition is 4, and the number of data rows of each data block is 60, 60, 60, and 20 respectively.
[0070] The writing module 140 is used to write each data block of the data to be written into the first data area, write the row data of each data block of the data to be written into the second data area, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area based on the number of the data blocks and the number of row data of each data block.
[0071] According to the number of data blocks after the data to be written is divided, and the byte space required to store the index information of each data block, the size of the space in the first index area that the data to be written needs to occupy is calculated, thereby obtaining the identification position of the data area; according to the number of rows and the byte space required to store the index information of each row, the size of the space in the second index area that the data to be written needs to occupy is calculated, thereby obtaining the identification position of the second data area.
[0072] According to the determined identification position of the data area storing the data to be written, the identification position of each data block of the data to be written is written into the first index area of the storage space, and according to the determined identification position of each data block of the data to be written in the second data area, the row data of each data block of the data to be written is written into the second data area of the storage space.
[0073] For example: the data blocks to be written after the data is divided into 4 blocks, and the byte space required to store the index information of each data block is 10, that is, the first index area of the data block in the storage space needs to occupy 40 (4*10) bytes of space, and the bytes are counted from 0. It can be known that the 40th byte is the identification position of the first data area of the storage space. Assuming that the first data block of the data to be written has 60 rows, the byte space required for the identification position of each row is 4, that is, the second index area of the first data block in the storage space needs to occupy 240 (60*4) bytes of space, it can be known that the 280th (240+40) byte is the identification position of the first data block in the second data area of the storage space.
[0074] Data writing specifically includes:
[0075] The identification position of the first data area and the second data area of the storage space is calculated according to the number of blocks after the data to be written is divided and the number of data rows in each block. Then the row data is written in the identification position of the second data area of the storage space, and the location information of the recorded row data is used as the index information of the row data. Finally, the index information of the recorded row data is written into the second index area of the storage space. After all data blocks are written, the index information of the data block is written into the first index area of the storage space. Because the space occupied by each row of data is different, the data is first written into the file and then the index information is written according to the actual occupied space, so that the appropriate storage space can be allocated according to the size of the written data. When writing the identification position of each row in the second index area, the number of data rows of the data block can also be written as the index information. Since the number of rows in the last block of the data to be written is usually less than the number of rows of other data blocks after the data to be written is divided, when reading the data, the number of rows stored in the second index area can be used to know how many rows of data the data block has.
[0076] In another embodiment, the data processing method also includes a data reading step: receiving a data reading request issued by the user, the data reading request including index information of the data to be read in the storage space; obtaining an identification position of the data to be read in a second index area in the storage space based on the index information; obtaining an identification position of the data to be read in a second data area in the storage space based on the identification position of the second index area, and reading the data based on the identification position of the second data area.
[0077] In addition, the present invention also provides a data processing method. Figure 3 , which is a schematic diagram of a method flow of an embodiment of the data processing method of the present invention. When the processor 12 of the electronic device 1 executes the data processing program 10 stored in the memory 11, the following steps of the data processing method are implemented:
[0078] Step S10: Divide the preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, divide the first data area into a second index area and a second data area according to a second preset ratio, and obtain the initial total number of rows of the storage space and the initial minimum number of rows per block of the storage space.
[0079] In this embodiment, the preset storage space is a medium required for data storage, such as a flash memory, a hard disk, a multimedia card, a card-type memory, etc. Data is written into the storage space in units of data blocks. The preset storage space of the storage device is divided into a first index area and a first data area according to a first preset ratio (for example, 1:20). The first index area stores the identification positions of the first block, the second block to the Nth block of data blocks in sequence. Each data block in the first data area is divided into a second index area and a second data area according to a second preset ratio (for example, 1:15). The second index area stores the identification positions of the first row, the second row to the Nth row of data of the data block in sequence. The second data area stores the first row, the second row to the Nth row of data of the data block in sequence. According to the data row identification position in the second index area, any row of data can be found in the second data area. If the data block is too large, the efficiency of searching for the row will be reduced; if the data block is too small, the number of data blocks will be too large, which will also reduce the efficiency of searching for the block. Therefore, the storage space is partitioned reasonably to obtain data blocks of moderate size. The initial total number of rows in the storage space = the maximum number of data blocks after the initial partitioning * the minimum number of rows in each data block after the initial partitioning.
[0080] The first data area is used to store data blocks written into the storage space, the first index area is used to store index information of the data blocks, the second data area is used to store row data of each data block, and the second index area is used to store index information of the row data of each data block.
[0081] Step S20: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written.
[0082] In this embodiment, the data to be written is taken as report data for example to illustrate this case. The report data writing request issued by the user includes the total number of rows of the report to be written.
[0083] Step S30: Compare the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result.
[0084] In this embodiment, before writing data into the storage space, it is necessary to perform a block operation on the data to be written, and the data to be written is taken as report data for explanation. If the total number of rows of the data to be written is greater than or equal to the initial total number of rows after the storage space is partitioned, the first calculation rule is used to calculate the number of data blocks after the data to be written is partitioned and the number of rows of each data block; if the total number of rows of the data to be written is less than the initial total number of rows after the storage space is partitioned, the second calculation rule is used to calculate the number of data blocks after the data to be written is partitioned and the number of rows of each data block.
[0085] Specifically, if the total number of rows of data to be written is greater than or equal to the initial total number of rows after the storage space is partitioned, the number of data blocks of data to be written = the total number of rows to be written / (the initial minimum number of rows per block of the storage space*a), where a is a positive integer greater than 1; if the number of rows of data to be written is less than the initial total number of rows, the number of data blocks of data to be written = (the total number of rows of data to be written + the initial minimum number of rows per block of the storage space) / the initial minimum number of rows per block of the storage space.
[0086] For example: the data to be written is 200 rows of report data, the initial total number of rows after the storage space is partitioned is 100, and the initial minimum number of rows in each block of the storage space is 60. Because the total number of rows of data to be written is less than the initial total number of rows after the storage space is partitioned (200<100×60), the second calculation rule is used to calculate the number of data blocks after the report is partitioned and the number of data rows of each data block, that is, the number of data blocks of the report = (200+60) / 60 = 4.3, and the result is integerized to obtain the number of data blocks of the report partition is 4, and the number of data rows of each data block is 60, 60, 60, and 20 respectively.
[0087] Step S40: Based on the number of data blocks and the number of row data of each data block, write each data block of the data to be written into the first data area, write the row data of each data block of the data to be written into the second data area, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area.
[0088] According to the number of data blocks after the data to be written is divided, and the byte space required to store the index information of each data block, the size of the space in the first index area that the data to be written needs to occupy is calculated, thereby obtaining the identification position of the data area; according to the number of rows and the byte space required to store the index information of each row, the size of the space in the second index area that the data to be written needs to occupy is calculated, thereby obtaining the identification position of the second data area.
[0089] According to the determined identification position of the data area storing the data to be written, the identification position of each data block of the data to be written is written into the first index area of the storage space, and according to the determined identification position of each data block of the data to be written in the second data area, the row data of each data block of the data to be written is written into the second data area of the storage space.
[0090] For example: the data blocks to be written after the data is divided into 4 blocks, and the byte space required to store the index information of each data block is 10, that is, the first index area of the data block in the storage space needs to occupy 40 (4*10) bytes of space, and the bytes are counted from 0. It can be known that the 40th byte is the identification position of the first data area of the storage space. Assuming that the first data block of the data to be written has 60 rows, the byte space required for the identification position of each row is 4, that is, the second index area of the first data block in the storage space needs to occupy 240 (60*4) bytes of space, it can be known that the 280th (240+40) byte is the identification position of the first data block in the second data area of the storage space.
[0091] Data writing specifically includes:
[0092] The index information of the data is written into the second index area of the storage space. After all data blocks are written, the index information of the data blocks is written into the first index area of the storage space. Because the space occupied by each row of data is different, the data is first written into the file and then the index information is written according to the actual occupied space. In this way, the appropriate storage space can be allocated according to the size of the written data. When writing the identification position of each row in the second index area, the number of data rows of the data block can also be written as index information. Since the number of rows in the last block of the data to be written is usually less than the number of rows in other data blocks after the data is divided into blocks, when reading the data, you can know how many rows of data the data block has through the number of rows information saved in the second index area.
[0093] In another embodiment, the data processing method also includes a data reading step: receiving a data reading request issued by the user, the data reading request including index information of the data to be read in the storage space; obtaining an identification position of the data to be read in a second index area in the storage space based on the index information; obtaining an identification position of the data to be read in a second data area in the storage space based on the identification position of the second index area, and reading the data based on the identification position of the second data area.
[0094] In addition, the embodiment of the present invention further proposes a computer-readable storage medium, which may be any one or any combination of a hard disk, a multimedia card, an SD card, a flash memory card, an SMC, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, etc. The computer-readable storage medium includes a data processing program 10, and when the data processing program 10 is executed by a processor, the following operations are implemented:
[0095] Initialization step: dividing a preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, dividing the first data area into a second index area and a second data area according to a second preset ratio, and obtaining an initial total number of rows of the storage space and an initial minimum number of rows per block of the storage space;
[0096] Receiving step: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written;
[0097] Block division step: comparing the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculating the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result; and
[0098] Writing steps: based on the number of data blocks and the number of row data of each data block, write each data block of the data to be written into the first data area, write the row data of each data block of the data to be written into the second data area, write the index information of the row data into the second index area, and write the index information of each data block of the data to be written into the first index area.
[0099] The specific implementation of the computer-readable storage medium of the present invention is substantially the same as the specific implementation of the above-mentioned data processing method, and will not be described in detail here.
[0100] It should be noted that the serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments. And the terms "including", "comprising" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method 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, device, article or method. In the absence of further restrictions, an element defined by the sentence "including a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0101] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, including a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, an electronic device, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0102] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A data processing method, applied to an electronic device, characterized in that: The method comprises: Initialization step: dividing the preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, dividing the first data area into a second index area and a second data area according to a second preset ratio, and obtaining the initial total number of rows of the storage space and the initial minimum number of rows per block of the storage space, the initial total number of rows of the storage space = the maximum number of initial data blocks of the storage space * the initial minimum number of rows per block of the storage space; Receiving step: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written; Block division step: comparing the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculating the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result; and Writing step: based on the number of the data blocks and the number of row data of each of the data blocks, writing each data block of the data to be written into the first data area, writing the row data of each data block of the data to be written into the second data area, writing the index information of the row data into the second index area, and writing the index information of each data block of the data to be written into the first index area; The block division step includes: when the total number of rows of the data to be written is greater than or equal to the initial total number of rows of the storage space, using a first calculation rule to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block; when the total number of rows of the data to be written is less than the initial total number of rows of the storage space, using a second calculation rule to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block; The first calculation rule includes: the number of data blocks corresponding to the data to be written = the total number of rows of the data to be written / (the minimum number of rows per block in the initial storage space × a), where a is a positive integer greater than 1 and less than the maximum number of the initial data blocks in the storage space; The second calculation rule includes: the number of data blocks corresponding to the data to be written = (the total number of rows of the data to be written + the initial minimum number of rows per block of the storage space) / the initial minimum number of rows per block of the storage space.
2. The data processing method according to claim 1, characterized in that: The method further comprises the step of reading: receiving a data reading request sent by the user, wherein the data reading request includes index information of the data to be read in the storage space; According to the index information, obtaining the identification position of the data to be read in the second index area in the storage space; According to the identification position of the second index area, the identification position of the data to be read in the second data area in the storage space is obtained, and the data is read according to the identification position of the second data area.
3. The data processing method according to any one of claims 1 to 2, characterized in that: The block division step further includes: Calculate the first index area memory space corresponding to the data to be written according to the number of the data blocks and the storage bytes of the index information of each data block, and determine the identification position of the first data area according to the first index area memory space; According to the number of row data and the index information storage bytes of each row data, a second index area memory space corresponding to the data to be written is calculated, and an identification position of the second data area is determined according to the second index area memory space.
4. An electronic device comprising a memory and a processor, characterized in that: The memory stores a data processing program, and the data processing program is executed by the processor to implement the following steps: Initialization step: dividing the preset storage space of the storage device into a first index area and a first data area according to a first preset ratio, dividing the first data area into a second index area and a second data area according to a second preset ratio, and obtaining the initial total number of rows of the storage space and the initial minimum number of rows per block of the storage space, wherein the initial total number of rows of the storage space = the maximum number of data blocks after initial partitioning * the minimum number of rows per data block after initial partitioning; Receiving step: receiving a request from a user to write data into the storage space, wherein the request includes the total number of rows of data to be written; Block division step: comparing the total number of rows of the data to be written with the initial total number of rows of the storage space, and calculating the number of data blocks corresponding to the data to be written and the number of row data of each data block according to the comparison result; and Writing step: based on the number of the data blocks and the number of row data of each of the data blocks, writing each data block of the data to be written into the first data area, writing the row data of each data block of the data to be written into the second data area, writing the index information of the row data into the second index area, and writing the index information of each data block of the data to be written into the first index area; The block division step includes: when the total number of rows of the data to be written is greater than or equal to the initial total number of rows of the storage space, using a first calculation rule to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block; when the total number of rows of the data to be written is less than the initial total number of rows of the storage space, using a second calculation rule to calculate the number of data blocks corresponding to the data to be written and the number of row data of each data block; The first calculation rule includes: the number of data blocks corresponding to the data to be written = the total number of rows of the data to be written / (the minimum number of rows per block in the initial storage space × a), where a is a positive integer greater than 1 and less than the maximum number of the initial data blocks in the storage space; The second calculation rule includes: the number of data blocks corresponding to the data to be written = (the total number of rows of the data to be written + the initial minimum number of rows per block of the storage space) / the initial minimum number of rows per block of the storage space.
5. The electronic device as claimed in claim 4, characterized in that: The data processing program is executed by the processor and also implements the reading step: receiving a data reading request sent by the user, wherein the data reading request includes index information of the data to be read in the storage space; According to the index information, obtaining the identification position of the data to be read in the second index area in the storage space; According to the identification position of the second index area, the identification position of the data to be read in the second data area in the storage space is obtained, and the data is read according to the identification position of the second data area.
6. The electronic device as claimed in claim 4, characterized in that: The block division step further includes: Calculate the first index area memory space corresponding to the data to be written according to the number of the data blocks and the storage bytes of the index information of each data block, and determine the identification position of the first data area according to the first index area memory space; According to the number of row data and the index information storage bytes of each row data, a second index area memory space corresponding to the data to be written is calculated, and an identification position of the second data area is determined according to the second index area memory space.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a data processing program, and when the data processing program is executed by a processor, the data processing method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Data cache method and system
CN101178693A
Method and apparatus for reading and writing video data in NAS device
CN106610967A
A Delta compressed storage component based on block-level data de-duplication
CN109445703A
File load times with dynamic storage usage
US20150039831A1
