A data storage method, apparatus, and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-20
- Publication Date
- 2026-08-14
AI Technical Summary
[0002]现有的数据存储方法在接收到消息数据并进行存储的情况下,通常是从内存资源中预先划分一个固定容量大小的缓存容量来进行存储,但是由于消息在未被读取时,无法预知需要划分多少容量的缓存容量,如果接收到的消息数据大于固定容量时,需要根据消息数据的数据量重新为消息数据划分缓存容量,并释放现有的固定缓存容量
[0031]This application provides a data storage method, apparatus, and storage medium. The method includes: upon receiving first message data, determining a first data volume, a reference index value, and a reference cache capacity corresponding to the first message data; comparing the first data volume and the reference cache capacity to obtain a comparison result; adjusting the reference index value according to the comparison result to obtain a first index value; searching for the first cache capacity corresponding to the first index value from a preset cache capacity library; and allocating cache space of the first cache capacity to store the first message data. By adopting the above implementation scheme, since memory resources are pre-divided into multiple cache capacities of different sizes and corresponding index values are added, when receiving message data, the index value corresponding to the message data can be obtained through the judgment result of the message data and the reference cache capacity, and then the cache capacity corresponding to the message data can be searched from the preset cache capacity library to store the message data, which can improve the efficiency of allocating cache capacity and thus reduce the storage time.
Smart Images

Figure CN115708078B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage, and in particular to a data storage method, apparatus, and storage medium. Background Technology
[0002] Existing data storage methods typically pre-allocate a fixed-size cache from memory resources when receiving and storing message data. However, since the required cache size is unpredictable before a message is read, if the received message data exceeds the fixed size, the cache size needs to be reallocated based on the message data volume, and the existing fixed cache size needs to be released. Therefore, finding the most suitable cache size for storing the received message data is inefficient and increases storage time. Summary of the Invention
[0003] This application provides a data storage method, apparatus, and storage medium that can improve the efficiency of allocating cache capacity and thus reduce storage time.
[0004] The technical solution of this application is implemented as follows:
[0005] In a first aspect, embodiments of this application provide a data storage method, the method comprising:
[0006] Upon receiving the first message data, determine the first data volume, the reference index value, and the reference cache capacity corresponding to the reference index value;
[0007] The first data volume and the reference cache capacity are compared to obtain a comparison result; the reference index value is adjusted according to the comparison result to obtain a first index value.
[0008] Find the first cache capacity corresponding to the first index value in the preset cache capacity library; allocate cache space of the first cache capacity to the first message data for data storage.
[0009] In the above data storage method, determining the reference index value and the reference cache capacity corresponding to the reference index value includes:
[0010] If the first message data is the first message data received, then the reference index value is determined to be the initial index value, and the reference cache capacity is the initial cache capacity corresponding to the initial index value;
[0011] If the first message data is not the first message data received, then the reference index value is determined to be the index value determined during the previous data storage, and the reference cache capacity is the cache capacity corresponding to the index value determined during the previous data storage.
[0012] In the above data storage method, adjusting the reference index value based on the comparison result to obtain the first index value includes:
[0013] The adjustment rules are determined based on the sorting method of the preset cache capacity library;
[0014] If the comparison result indicates that the first data volume is greater than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rule until the cache capacity corresponding to the adjusted reference index value is greater than the first data volume, and the adjusted reference index value is determined as the first index value.
[0015] In the above data storage method, adjusting the reference index value based on the comparison result to obtain a first index value includes:
[0016] The adjustment rules are determined based on the sorting method of the preset cache capacity library;
[0017] If the comparison result is that the first data volume is less than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rule until the cache capacity corresponding to the adjusted reference index value is less than the first data volume.
[0018] According to the adjustment rules, the previous round of adjusted reference index value adjacent to the adjusted reference index value is determined, and the previous round of adjusted reference index value is determined as the first index value.
[0019] In the above data storage method, adjusting the reference index value based on the comparison result to obtain the first index value includes:
[0020] If the comparison result indicates that the first data volume is less than the reference cache capacity, the reference index value is determined as the first index value.
[0021] In the above data storage method, before determining the first data volume, reference index value, and reference cache capacity corresponding to the first message data upon receiving the first message data, the method further includes:
[0022] According to the size of the cache capacity, index values are assigned to the cache capacity in sequence; and the cache capacity and the corresponding index value are added to the preset cache capacity library.
[0023] In the above data storage method, after searching for the first cache capacity corresponding to the first index value from the preset cache capacity library and allocating cache space of the first cache capacity to the first message data for data storage, the method further includes:
[0024] The first index value and the first cache capacity are used as the reference index value and the reference cache capacity, respectively, to determine the next allocated cache capacity when message data is received next time.
[0025] Secondly, embodiments of this application provide a data storage device, the device comprising:
[0026] The determining unit is configured to, upon receiving first message data, determine the first data volume, the reference index value, and the reference cache capacity corresponding to the reference index value;
[0027] A data processing unit is configured to compare the first data volume with the reference cache capacity to obtain a comparison result; and adjust the reference index value according to the comparison result to obtain a first index value.
[0028] The lookup unit is used to look up the first cache capacity corresponding to the first index value from the preset cache capacity library; and to allocate cache space of the first cache capacity to the first message data for data storage.
[0029] Thirdly, embodiments of this application provide a data storage device, characterized in that the device includes: a processor, a memory, and a communication bus; when the processor executes a running program stored in the memory, it implements the data storage method as described in any of the above claims.
[0030] Fourthly, embodiments of this application provide a storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the data storage method as described in any of the preceding claims.
[0031] This application provides a data storage method, apparatus, and storage medium. The method includes: upon receiving first message data, determining a first data volume, a reference index value, and a reference cache capacity corresponding to the first message data; comparing the first data volume and the reference cache capacity to obtain a comparison result; adjusting the reference index value according to the comparison result to obtain a first index value; searching for the first cache capacity corresponding to the first index value from a preset cache capacity library; and allocating cache space of the first cache capacity to store the first message data. By adopting the above implementation scheme, since memory resources are pre-divided into multiple cache capacities of different sizes and corresponding index values are added, when receiving message data, the index value corresponding to the message data can be obtained through the judgment result of the message data and the reference cache capacity, and then the cache capacity corresponding to the message data can be searched from the preset cache capacity library to store the message data, which can improve the efficiency of allocating cache capacity and thus reduce the storage time. Attached Figure Description
[0032] Figure 1 A flowchart illustrating a data storage method provided in this application embodiment;
[0033] Figure 2 A schematic diagram of the composition structure of a data storage device 1 provided in an embodiment of this application;
[0034] Figure 3 This is a schematic diagram of the composition structure of a data storage device 1 provided in an embodiment of this application. Detailed Implementation
[0035] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit the scope of this application.
[0036] This application provides a data storage method applied to a data storage device. Figure 1 A flowchart of a data storage method provided in an embodiment of this application is shown below. Figure 1 As shown, data storage methods may include:
[0037] S101. Upon receiving the first message data, determine the first data volume, reference index value, and reference cache capacity corresponding to the first message data.
[0038] The data storage method provided in this application embodiment is applicable to scenarios where cache capacity needs to be allocated for storage when message data is received.
[0039] In this embodiment of the application, when the data storage device receives the first message data, it determines the first data volume corresponding to the first message data, the reference index value, and the reference cache capacity corresponding to the reference index value.
[0040] It should be noted that when the first message data is received, it is necessary to allocate cache capacity for storing the first message data. At this time, it is necessary to first determine the first data volume corresponding to the first message data, and then determine how much cache capacity to allocate to the first message data based on the first data volume.
[0041] It should be noted that the reference index value can be understood as a reference when allocating cache capacity this time. The reference index value can be the initial index value or the index value corresponding to the cache capacity allocated in the last cache capacity allocation.
[0042] Specifically, if the first message data is the first message data received, then the reference index value is determined to be the initial index value, and the reference cache capacity is the initial cache capacity corresponding to the initial index value; if the first message data is not the first message data received, then the reference index value is determined to be the index value determined during the previous data storage, and the reference cache capacity is the cache capacity corresponding to the index value determined during the previous data storage.
[0043] It should be noted that, assuming the first message data is the first received message data, since no message data has been received and stored before, the reference index value at this time can only be the initially specified index value. In this embodiment, the initial index value is 32, and the corresponding initial cache capacity is 1024 bytes. The specific initial index value and initial cache capacity are specified according to the actual situation, and this embodiment does not limit them here.
[0044] It should be noted that, assuming the first message data is not the first message data received, the index value determined when the message was stored last time is the reference index value. For example, if the message data was received last time and stored in a cache space with a capacity of 512 bytes, and its corresponding index value was 31, then the reference index value is 31 and the reference cache capacity is 512 bytes.
[0045] It should be noted that the default cache capacity library consists of multiple different cache capacities, and each cache capacity has its own index value.
[0046] Specifically, according to the size of the cache capacity, index values are assigned to the cache capacity in sequence; and the cache capacity and the corresponding index value are added to the preset cache capacity library.
[0047] For example, in this embodiment of the application, a preset cache capacity library A is defined, A = [16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272, 288, 304, 320, 336, 352, 368, 384, 400, 416, 432, 448, 464, 48]. 0, 496, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435 [456, 536870912, 1073741824] From this preset cache capacity library A, it can be seen that the preset minimum cache capacity is 16 bytes and the maximum cache capacity is 1073741824 bytes. A corresponding index value can be added to each cache capacity. For example, 16 bytes corresponds to index value 0, 32 bytes to index value 1, 48 bytes to index value 2, and so on, until each cache capacity has its own corresponding index value. Furthermore, from this preset cache capacity library A, it can be seen that when the cache capacity is less than 512 bytes, since the cache capacity is already relatively small, the reduction in capacity each time is smaller, with a difference of 16 bytes between every two cache capacities. When the capacity is greater than 512 bytes, it indicates that the message stream to be decoded is relatively large, and a larger reduction is used, with a multiple relationship between every two cache capacities.
[0048] It should be noted that when defining the preset cache capacity library, it can be stored from largest to smallest according to the size of the cache capacity, for example: [144, 128, 112, 96, 80, 64, 48, 32, 16]. In this case, the index value corresponding to the cache capacity of 144 is 0, and the index value corresponding to the cache capacity of 16 is 8. The specific method for generating the preset cache capacity library is determined according to the actual situation, and this application embodiment does not limit it here.
[0049] S102. Compare the first data volume with the reference cache capacity to obtain the comparison result; adjust the reference index value according to the comparison result to obtain the first index value.
[0050] In this embodiment of the application, when the data storage device finds the reference cache capacity corresponding to the reference index value, it compares the first data volume with the reference cache capacity to obtain a comparison result; and adjusts the reference index value according to the comparison result to obtain the first index value.
[0051] In one optional embodiment of this application, if the first data volume is greater than the reference cache capacity, the cache capacity needs to be increased based on the reference cache capacity to store the first message data.
[0052] Specifically, the adjustment rules are determined based on the sorting method of the preset cache capacity library; if the comparison result is that the first data volume is greater than the reference cache capacity, the reference index value is adjusted cyclically according to the first preset value and the adjustment rules until the cache capacity corresponding to the adjusted reference index value is greater than the first data volume, and the adjusted reference index value is determined as the first index value.
[0053] It should be noted that the sorting method of the preset cache capacity library can be understood as storing caches from smallest to largest or from largest to smallest.
[0054] It should be noted that, assuming the default cache size is stored in ascending order, the adjustment rule is to cyclically increase the first default value based on the reference index value; assuming the default cache size is stored in descending order, the adjustment rule is to cyclically decrease the first default value based on the reference index value.
[0055] For example, suppose the preset cache capacity library is sorted from smallest to largest, and the first data volume is 2000 bytes, while the reference cache capacity is 512 bytes. The 512-byte reference cache capacity cannot store the 2000 bytes of the first message data, so the cache capacity needs to be increased. Therefore, a first preset value is added to the reference index value 31. In this embodiment, the first preset value is 4. Adding 4 to 31 yields index value 35. Then, the cache capacity corresponding to index value 35 in the preset cache capacity library is found to be 8192 bytes. It is determined whether the 2000 bytes of the first message data can be stored in the cache capacity corresponding to index value 35. If so, index value 35 becomes the first index value. However, if the first data volume is 9000 bytes, it cannot be stored in the cache capacity corresponding to index value 35. The first preset value of 4 needs to be added to index value 35 again, yielding index value 39. This process continues until the cache capacity corresponding to the adjusted reference index value is greater than the first data volume, at which point the first index value is obtained.
[0056] It should be noted that during the cyclic increment process, the increased index value must not exceed the maximum index value in the preset cache capacity library; during the cyclic decrement process, the decreased index value must not be less than the minimum index value in the preset cache capacity library.
[0057] In one optional embodiment of this application, if the first data volume is less than the reference cache capacity, the cache capacity needs to be reduced based on the reference cache capacity in order to store the first message data.
[0058] Specifically, the adjustment rules are determined according to the sorting method of the preset cache capacity library; if the comparison result is that the first data volume is less than the reference cache capacity, the reference index value is adjusted cyclically according to the first preset value and the adjustment rules until the cache capacity corresponding to the adjusted reference index value is less than the first data volume; according to the adjustment rules, the previous round of adjusted reference index value is determined and the previous round of adjusted reference index value is determined as the first index value.
[0059] It should be noted that, assuming the default cache capacity library is stored in ascending order, the adjustment rule is to cyclically decrease the second default value based on the reference index value; assuming the default cache capacity library is stored in descending order, the adjustment rule is to cyclically increase the second default value based on the reference index value.
[0060] For example, suppose the preset cache capacity library is stored in ascending order, and the first data volume is 450 bytes, while the reference cache capacity is 512 bytes. Since the 512-byte reference cache capacity is greater than the 450-byte first message data, the cache capacity needs to be reduced based on the 512-byte reference cache capacity. This is done by subtracting a second preset value from the reference index value 31. In this embodiment, the second preset value is 1. Subtracting 1 from 31 yields the index value 30. Then, the cache capacity corresponding to the index value 30 in the preset cache capacity library is found to be 496 bytes. It is then determined whether the cache capacity 496 corresponding to the index value 30 is less than the 450 bytes of the first message data. If it is not less, the second preset value is further subtracted from the index value 30, and the determination is continued until the cache capacity corresponding to the adjusted reference index value is less than 450 bytes, i.e., the cache capacity in the preset cache capacity library is 448. At this point, a second preset value needs to be added to the reference index value corresponding to the 448 cache capacity, i.e., 1 is added, resulting in a cache capacity of 464. The index value corresponding to the 464 cache capacity is then used as the first index value.
[0061] Understandably, the above method can find a cache size that is as close as possible to the first data volume, thereby reducing the waste of memory resources.
[0062] In one optional embodiment of this application, if the first data volume is less than the reference cache capacity, the reference index value can be directly determined as the first index value.
[0063] S103. Find the first cache capacity corresponding to the first index value from the preset cache capacity library; allocate cache space of the first cache capacity for the first message data for data storage.
[0064] In this embodiment, the data storage device, upon obtaining the first index value, searches for the first cache capacity corresponding to the first index value in a preset cache capacity library; and allocates cache space of the first cache capacity for the first message data for data storage.
[0065] It should be noted that after allocating a cache space of the first cache capacity for storing the first message data, the first index value and the first cache capacity also need to be used as a reference for the next data storage.
[0066] Specifically, the first index value and the first cache capacity are used as reference index value and reference cache capacity to determine the cache capacity to be allocated next time message data is received.
[0067] For example, suppose the first index value is determined to be 33, the first cache capacity is 2048 bytes, and the reference index value is 31, the reference cache capacity is 512 bytes. Then the reference index value is updated to the first index value 33, and the reference cache capacity is updated to the first cache capacity 2048 bytes. When message data is received next time, the allocated cache capacity is determined based on the reference index value 33 and the reference cache capacity 2048 bytes.
[0068] This application provides a data storage method, which includes: upon receiving first message data, determining a first data volume, a reference index value, and a reference cache capacity corresponding to the first message data; comparing the first data volume and the reference cache capacity to obtain a comparison result; adjusting the reference index value according to the comparison result to obtain a first index value; searching for the first cache capacity corresponding to the first index value from a preset cache capacity library; and allocating cache space of the first cache capacity to store the first message data. By adopting the above implementation scheme, firstly, by pre-dividing memory resources into multiple cache capacities of different sizes and adding corresponding index values, upon receiving message data, the index value corresponding to the message data can be obtained through the judgment result of the message data and the reference cache capacity, and then the cache capacity corresponding to the message data can be searched from the preset cache capacity library to store the message data. This improves the efficiency of allocating cache capacity and thus reduces storage time.
[0069] Based on the above embodiments, in another embodiment of this application, a data storage device 1 is provided. Figure 2 A schematic diagram of the composition structure of a data storage device 1 provided in this application Figure 1 ,like Figure 2As shown, the data storage device 1 includes:
[0070] The determining unit 10 is used to determine, upon receiving the first message data, the first data volume corresponding to the first message data, the reference index value, and the reference cache capacity corresponding to the reference index value;
[0071] Data processing unit 11 is used to compare the first data volume with the reference cache capacity to obtain a comparison result; and to adjust the reference index value according to the comparison result to obtain a first index value.
[0072] The lookup unit 12 is used to look up the first cache capacity corresponding to the first index value from the preset cache capacity library; and to allocate cache space of the first cache capacity to the first message data for data storage.
[0073] Optionally, the determining unit 10 is further configured to determine the reference index value as an initial index value if the first message data is the first message data received, and the reference cache capacity is the initial cache capacity corresponding to the initial index value;
[0074] The determining unit 10 is further configured to, if the first message data is not the first message data received, determine that the reference index value is the index value determined during the previous data storage, and the reference cache capacity is the cache capacity corresponding to the index value determined during the previous data storage.
[0075] Optionally, the data processing unit 11 is further configured to determine adjustment rules according to the sorting method of the preset cache capacity library; if the comparison result is that the first data volume is greater than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rules until the cache capacity corresponding to the adjusted reference index value is greater than the first data volume, and the adjusted reference index value is determined as the first index value.
[0076] Optionally, the data processing unit 11 is further configured to determine adjustment rules according to the sorting method of the preset cache capacity library; if the comparison result is that the first data volume is less than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rules until the cache capacity corresponding to the adjusted reference index value is less than the first data volume; according to the adjustment rules, the previous round of adjusted reference index value adjacent to the adjusted reference index value is determined, and the previous round of adjusted reference index value is determined as the first index value.
[0077] Optionally, the determining unit 10 is further configured to determine the reference index value as the first index value if the comparison result is that the first data volume is less than the reference cache capacity.
[0078] Optionally, the data processing unit 11 is further configured to allocate index values to the cache capacity in sequence according to the size of the cache capacity; and add the cache capacity and the corresponding index value to the preset cache capacity library.
[0079] Optionally, the data processing unit 11 is further configured to use the first index value and the first cache capacity as the reference index value and the reference cache capacity, so as to determine the cache capacity to be allocated next time when message data is received next time.
[0080] This application provides a data storage device, which includes: upon receiving first message data, determining a first data volume, a reference index value, and a reference cache capacity corresponding to the first message data; comparing the first data volume and the reference cache capacity to obtain a comparison result; adjusting the reference index value according to the comparison result to obtain a first index value; searching for the first cache capacity corresponding to the first index value from a preset cache capacity library; and allocating cache space of the first cache capacity to store the first message data. By adopting the above implementation scheme, since memory resources are pre-divided into multiple cache capacities of different sizes and corresponding index values are added, upon receiving message data, the index value corresponding to the message data can be obtained through the judgment result of the message data and the reference cache capacity, and then the cache capacity corresponding to the message data can be searched from the preset cache capacity library to store the message data. This improves the efficiency of allocating cache capacity and reduces storage time.
[0081] Figure 3 A schematic diagram of the composition structure of a data storage device 1 provided in this application embodiment. Figure 2 In practical applications, based on the same disclosed concept of the above embodiments, such as Figure 3 As shown, the data storage device 1 in this embodiment includes: a processor 13, a memory 14, and a communication bus 15.
[0082] In a specific embodiment, the determining unit 10, data processing unit 11, and searching unit 12 can be implemented by a processor 13 located on the data storage device 1. The processor 13 can be at least one of the following: Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), CPU, controller, microcontroller, or microprocessor. It is understood that for different data storage devices, the electronic device used to implement the processor function can also be other types; this embodiment does not impose specific limitations.
[0083] In this embodiment, the communication bus 15 is used to realize the connection communication between the processor 13 and the memory 14; when the processor 13 executes the running program stored in the memory 14, it implements the following data storage method:
[0084] Upon receiving the first message data, determine the first data volume, the reference index value, and the reference cache capacity corresponding to the reference index value;
[0085] The first data volume and the reference cache capacity are compared to obtain a comparison result; the reference index value is adjusted according to the comparison result to obtain a first index value.
[0086] Find the first cache capacity corresponding to the first index value in the preset cache capacity library; allocate cache space of the first cache capacity to the first message data for data storage.
[0087] Optionally, the processor 13 is further configured to: if the first message data is message data received for the first time, determine the reference index value as an initial index value, and the reference cache capacity as the initial cache capacity corresponding to the initial index value; if the first message data is message data not received for the first time, determine the reference index value as an index value determined during the previous data storage, and the reference cache capacity as the cache capacity corresponding to the index value determined during the previous data storage.
[0088] Optionally, the processor 13 is further configured to determine adjustment rules according to the sorting method of the preset cache capacity library; if the comparison result is that the first data volume is greater than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rules until the cache capacity corresponding to the adjusted reference index value is greater than the first data volume, and the adjusted reference index value is determined as the first index value.
[0089] Optionally, the processor 13 is further configured to determine adjustment rules according to the sorting method of the preset cache capacity library; if the comparison result is that the first data volume is less than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rules until the cache capacity corresponding to the adjusted reference index value is less than the first data volume; according to the adjustment rules, the previous round of adjusted reference index value adjacent to the adjusted reference index value is determined, and the previous round of adjusted reference index value is determined as the first index value.
[0090] Optionally, the processor 13 is further configured to determine the reference index value as the first index value if the comparison result is that the first data volume is less than the reference cache capacity.
[0091] Optionally, the processor 13 is further configured to allocate index values to the cache capacity in sequence according to the size of the cache capacity; and add the cache capacity and the corresponding index value to the preset cache capacity library.
[0092] Optionally, the processor 13 is further configured to use the first index value and the first cache capacity as the reference index value and the reference cache capacity, so as to determine the cache capacity to be allocated next time when message data is received next time.
[0093] This application provides a storage medium storing a computer program thereon. The computer-readable storage medium stores one or more programs, which can be executed by one or more processors and applied in a data storage device. The computer program implements the data storage method described above.
[0094] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0095] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause an image display device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the data storage methods described in the various embodiments of this disclosure.
[0096] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application.
Claims
1. A data storage method, characterized in that, The method includes: Upon receiving the first message data, determine the first data volume, the reference index value, and the reference cache capacity corresponding to the reference index value; The first data volume and the reference cache capacity are compared to obtain a comparison result; the reference index value is adjusted according to the comparison result to obtain a first index value. Find the first cache capacity corresponding to the first index value in the preset cache capacity library; allocate cache space of the first cache capacity to the first message data for data storage.
2. The method according to claim 1, characterized in that, Determining the reference index value and the corresponding reference cache capacity includes: If the first message data is the first message data received, then the reference index value is determined to be the initial index value, and the reference cache capacity is the initial cache capacity corresponding to the initial index value; If the first message data is not the first message data received, then the reference index value is determined to be the index value determined during the previous data storage, and the reference cache capacity is the cache capacity corresponding to the index value determined during the previous data storage.
3. The method according to claim 1, characterized in that, The step of adjusting the reference index value based on the comparison result to obtain the first index value includes: The adjustment rules are determined based on the sorting method of the preset cache capacity library; If the comparison result indicates that the first data volume is greater than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rule until the cache capacity corresponding to the adjusted reference index value is greater than the first data volume, and the adjusted reference index value is determined as the first index value.
4. The method according to claim 1, characterized in that, The step of adjusting the reference index value based on the comparison result to obtain the first index value includes: The adjustment rules are determined based on the sorting method of the preset cache capacity library; If the comparison result is that the first data volume is less than the reference cache capacity, then the reference index value is adjusted cyclically according to the first preset value and the adjustment rule until the cache capacity corresponding to the adjusted reference index value is less than the first data volume. According to the adjustment rules, the previous round of adjusted reference index value adjacent to the adjusted reference index value is determined, and the previous round of adjusted reference index value is determined as the first index value.
5. The method according to claim 1, characterized in that, The step of adjusting the reference index value based on the comparison result to obtain the first index value includes: If the comparison result indicates that the first data volume is less than the reference cache capacity, the reference index value is determined as the first index value.
6. The method according to claim 1, characterized in that, Before determining the first data volume, reference index value, and reference cache capacity corresponding to the reference index value upon receiving the first message data, the method further includes: According to the size of the cache capacity, index values are assigned to the cache capacity in sequence; and the cache capacity and the corresponding index value are added to the preset cache capacity library.
7. The method according to claim 1, characterized in that, The first cache capacity corresponding to the first index value is retrieved from the preset cache capacity library; After allocating cache space of the first cache capacity to the first message data for data storage, the method further includes: The first index value and the first cache capacity are used as the reference index value and the reference cache capacity, respectively, to determine the next allocated cache capacity when message data is received next time.
8. A data storage device, characterized in that, The device includes: The determining unit is configured to, upon receiving first message data, determine the first data volume, the reference index value, and the reference cache capacity corresponding to the reference index value; A data processing unit is configured to compare the first data volume with the reference cache capacity to obtain a comparison result; and adjust the reference index value according to the comparison result to obtain a first index value. The lookup unit is used to look up the first cache capacity corresponding to the first index value from the preset cache capacity library; and to allocate cache space of the first cache capacity to the first message data for data storage.
9. A data storage device, characterized in that, The device includes: a processor, a memory, and a communication bus; when the processor executes the running program stored in the memory, it implements the method as described in any one of claims 1-7.
10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Cache space distribution method and device
CN103778071A
Data storage method and system, storage medium and electronic equipment
CN110688379A