Dynamic memory management method based on single queue, electronic device and medium

By introducing dynamic management of main memory and auxiliary memory into a one-way queue, the problem of high frequency of queue element copying and release is solved, and memory utilization is improved.

CN121387570BActive Publication Date: 2026-03-27成都融见软件科技有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-24
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

In existing technologies, queues without a specified container capacity undergo frequent copying and memory release of queue elements during dynamic changes, resulting in low memory utilization.

Method used

A dynamic memory management method using a unidirectional queue is adopted. By initializing the main memory and auxiliary memory of the queue, the main memory is used to store elements first. When the main memory is insufficient, the auxiliary memory is activated to expand the memory capacity and reduce the frequency of element copying and releasing.

Benefits of technology

This reduces the frequency of copying and releasing queue elements during dynamic changes in a one-way queue, thereby improving the utilization rate of queue memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121387570B_ABST
    Figure CN121387570B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of memory management, in particular to a dynamic memory management method based on a one-way queue, electronic equipment and a medium. The application stores queue elements in the mode of setting a queue main memory and a queue auxiliary memory, first activates the queue main memory, then activates the queue auxiliary memory, and when the queue main memory and the queue auxiliary memory cannot meet the storage requirements of the queue elements, the size of the queue main memory and the queue auxiliary memory is updated to expand the capacity, the frequency of copying and releasing the memory of the queue elements in the dynamic change process of the one-way queue is reduced, and the queue memory utilization rate of the one-way queue is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of memory management, in particular to a dynamic memory management method based on a one-way queue, an electronic device and a medium. BACKGROUND

[0002] A queue includes a queue with a specified capacity and a queue without a specified container capacity. For the queue without a specified container capacity, unlimited queue elements can be added or deleted. In the prior art, an initial memory is allocated for the queue without a specified container capacity. When the initial memory is insufficient to meet the memory requirement, a larger capacity memory needs to be applied, the queue elements in the original memory are copied to the newly applied memory, and the original memory is released. In general, the newly applied memory is an integer multiple of the original memory, which is easy to cause long-term idling of the allocated memory and low memory utilization. In addition, each time a larger capacity memory is applied, all queue elements need to be copied to the newly applied memory, and the original memory is released, which is high in frequency of queue element copying and memory releasing. The deletion operation of the data of the queue without a specified container capacity can further cause the memory idling problem. When the memory idling occurs, a smaller memory can be applied to copy all queue elements in the original memory to the smaller memory and release the original memory, but this further increases the frequency of queue element copying and memory releasing. Therefore, how to reduce the frequency of queue element copying and memory releasing in the dynamic change process of the queue and improve the queue memory utilization has become a technical problem to be solved. SUMMARY

[0003] The present application aims to provide a dynamic memory management method based on a one-way queue, an electronic device and a medium, which reduces the frequency of queue element copying and memory releasing in the dynamic change process of the one-way queue and improves the queue memory utilization of the one-way queue.

[0004] According to a first aspect of the present application, a dynamic memory management method based on a one-way queue is provided, comprising:

[0005] Step S1, initializing a queue main memory with a memory size Ca, and initially setting a current queue element number Ba=0, wherein the queue is a one-way queue without a specified container capacity;

[0006] Step S2, obtaining a queue element to be inserted into the queue, and if BaCa, executing step S3, otherwise, executing step S4;

[0007] Step S3, inserting the queue element to be inserted into the queue main memory, setting Ba=Ba+1, and returning to step S2;

[0008] Step S4, if Ba=Ca, executing step S6, otherwise, executing step S5;

[0009] If Ba=2xCa, step S8 is executed, otherwise, step S7 is executed.

[0010] In step S6, a queue auxiliary memory with a size of Ca is initialized, the queue auxiliary memory and the queue main memory are set as logically continuous queue memories, and step S7 is executed.

[0011] In step S7, the queue element to be inserted is inserted into the queue auxiliary memory, Ba is set as Ba+1, and step S2 is returned.

[0012] In step S8, Ca is set as 2xCa, a new queue main memory with a size of Ca is initialized, the queue elements in the original queue main memory and the queue auxiliary memory are written into the new queue main memory, the original queue main memory and the queue auxiliary memory are released, a new queue auxiliary memory with a size of Ca is initialized, the queue element to be inserted is inserted into the new queue auxiliary memory, and step S2 is returned.

[0013] According to a second aspect of the present application, an electronic device is provided, comprising at least one processor, and a memory connected with the at least one processor in communication; wherein the memory stores instructions executed by the at least one processor, and the instructions are configured to execute the method according to the first aspect of the present application.

[0014] According to a third aspect of the present application, a computer readable storage medium is provided, which stores computer executable instructions, and the computer executable instructions are configured to execute the method according to the first aspect of the present application.

[0015] Compared with the prior art, the present application has obvious advantages and beneficial effects. By means of the above technical scheme, the present application provides a dynamic memory management method based on a one-way queue, an electronic device and a medium, which can achieve considerable technical progress and practicability, and have wide industrial utilization value, and at least have the following beneficial effects:

[0016] The present application stores queue elements by setting a queue main memory and a queue auxiliary memory, enables the queue main memory first, then enables the queue auxiliary memory, and when the queue main memory and the queue auxiliary memory are insufficient to meet the queue element storage requirement, the size of the queue main memory and the queue auxiliary memory is updated to expand, which reduces the frequency of queue element copying and memory releasing in the dynamic change process of the one-way queue, and improves the queue memory utilization rate of the one-way queue. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed in the embodiments description. Obviously, the drawings in the following description only show some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained based on these drawings without any creative effort.

[0018] Figure 1 The flow chart of the dynamic memory management method based on the one-way queue provided by the embodiments of the present application. DETAILED DESCRIPTION

[0019] The technical solutions in the embodiments of the present application will be described clearly and completely in the following with reference to the drawings of the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without any creative effort are within the protection scope of the present application.

[0020] The embodiments of the present application provide a dynamic memory management method based on a one-way queue, as shown in the following figure, which comprises the following steps. Figure 1

[0021] Step S1, initialize a queue main memory with a memory size of Ca, and initially set the current queue element number Ba=0, wherein the queue is a one-way queue without a specified container capacity.

[0022] The one-way queue refers to a queue in which queue elements can only be inserted or deleted at the head or at the tail. The queue can be generated based on SystemVerilog, C++, Java, Go, Swift, etc.

[0023] Step S2, obtain a queue element to be inserted into the queue, and if BaCa, execute step S3, otherwise, execute step S4.

[0024] It can be understood that if BaCa, it means that the size of the current queue main memory can meet the storage requirement of the queue element, therefore, the queue element to be inserted can be directly inserted into the queue main memory through step S3.

[0025] Step S3, insert the queue element to be inserted into the queue main memory, set Ba=Ba+1, and return to step S2.

[0026] It should be noted that since it is a one-way queue, the physical order of the queue elements in the queue main memory is the same as that of the double-way queue, therefore, the queue element to be inserted can be directly inserted into the queue main memory in order.

[0027] ​Step S4, if Ba=Ca, execute step S6, otherwise, execute step S5.

[0028] It should be noted that, if Ba=Ca, at this time the queue main memory has been full, at this time, the queue auxiliary memory is enabled through step S6. It can be understood that the queue auxiliary memory is not started before the queue main memory meets the queue element storage requirements, reducing the idle memory and improving the queue memory utilization.

[0029] Step S5, if Ba=2xCa, execute step S8, otherwise, execute step S7.

[0030] It should be noted that, in step S5, when Ba≠2xCa, at this time, Ca<Ba<2xCa is met, the queue element to be inserted is inserted into the queue auxiliary memory.

[0031] Step S6, initialize the queue auxiliary memory with a size of Ca, set the queue auxiliary memory and the queue main memory as logically continuous queue memory, and execute step S7.

[0032] It should be noted that the queue auxiliary memory is a physically continuous memory, and the queue auxiliary memory is also a physically continuous memory. The queue auxiliary memory and the queue main memory can be physically continuous or discontinuous, but setting the queue auxiliary memory and the queue main memory as logically continuous queue memory can be logically understood as the last memory unit of the queue auxiliary memory being connected to the first memory unit of the queue auxiliary memory.

[0033] Step S7, insert the queue element to be inserted into the queue auxiliary memory, set Ba=Ba+1, and return to step S2.

[0034] Step S8, set Ca=2xCa, initialize a new queue main memory with a size of Ca, re-write the queue elements in the original queue main memory and the queue auxiliary memory into the new queue main memory, release the original queue main memory and the queue auxiliary memory, initialize a new queue auxiliary memory with a size of Ca, insert the queue element to be inserted into the new queue auxiliary memory, and return to step S2.

[0035] It should be noted that, since it is a single queue, the physical order of the queue elements in the queue memory composed of the queue main memory and the queue auxiliary memory is the same as that of the double queue, so the queue elements in the original queue main memory and the queue auxiliary memory can be directly re-written into the new queue main memory.

[0036] The embodiment of the present application uses the queue main memory and the queue auxiliary memory in cooperation, enables the queue main memory first, stores the queue elements into the queue main memory, and enables the queue auxiliary memory when the queue main memory is insufficient to meet the queue element storage requirement, so that the queue elements in the queue main memory do not need to be copied again and the queue main memory does not need to be released, thereby reducing the frequency of copying and releasing the memory of the queue elements in the process of dynamic change of the queue. When the queue auxiliary memory is also insufficient to meet the memory requirement, a new queue main memory and a new auxiliary memory with larger capacity are set, and the original queue main memory and the queue auxiliary memory are released, so that the queue main memory and the queue auxiliary memory are used in cooperation, which can reduce the idle condition of the memory and improve the utilization rate of the queue memory.

[0037] As an embodiment, the queue supports inserting or deleting the queue elements at the tail, and the step S8 of re-writing the queue elements in the original queue main memory and the queue auxiliary memory into the new queue main memory comprises:

[0038] The step S81 directly splices and stores the queue elements in the original queue main memory and the queue auxiliary memory into the new queue main memory.

[0039] It should be noted that, since the queue is a single-direction queue, only the insertion of the queue elements at the tail is supported in the present example, the queue auxiliary memory and the queue main memory are set as the logically continuous queue memory, therefore, the physical storage order of the queue elements in the original queue main memory and the queue auxiliary memory is consistent with the storage order of the queue elements in the queue, so that the queue elements in the original queue main memory and the queue auxiliary memory can be directly spliced and stored into the new queue main memory.

[0040] It should be noted that, the queue can also support the insertion or deletion of the queue elements at the head, which is similar to the insertion or deletion of the queue elements at the tail, and will not be described again.

[0041] As an embodiment, the queue main memory comprises Ca memory units, the queue auxiliary memory comprises Ca memory units, the queue elements in the queue, the memory units in the queue main memory and the memory units in the queue auxiliary memory are numbered in sequence from x, specifically, all are numbered in sequence from x with the same length and increasing, x can take values of 0, 1, 2, 3,..., and preferably, x takes values of 0 or 1. The method further comprises:

[0042] The step S10 acquires a queue element to be accessed label Q, Q is the corresponding sequence number of the queue element to be accessed in the queue.

[0043] The step S20 executes the step S30 if the queue element to be accessed label is less than or equal to x+Ca-1, otherwise, executes the step S40.

[0044] It should be noted that if the to-be-accessed queue element label is less than or equal to x+Ca-1, it indicates that the to-be-accessed queue element is located in the queue main memory, and if the to-be-accessed queue element label is greater than x+Ca-1, it indicates that the to-be-accessed queue element is located in the queue auxiliary memory.

[0045] Step S30, the queue element in the memory unit with label Q in the queue main memory is determined as the to-be-accessed queue element, and the process returns and ends.

[0046] Step S40, the queue element in the memory unit with label Q-Ca in the queue auxiliary memory is determined as the to-be-accessed queue element, and the process returns and ends.

[0047] It should be noted that through steps S10-S40, the queue element in the queue memory can be quickly and accurately accessed based on the corresponding serial number of the to-be-accessed queue element in the queue.

[0048] Not only can the queue element be inserted, but also can be deleted. As an embodiment, the method further comprises:

[0049] Step C00, if a queue element deletion instruction is received, the first queue element at the tail of the queue is deleted from the queue memory, and Ba=Ba-1 is set.

[0050] It should be noted that if the number of queue elements to be deleted exists in the queue element deletion instruction, the queue elements at the tail can also be deleted in batches.

[0051] As the number of deleted queue elements increases, the number of idle queue memory also increases. In order to increase the utilization rate of the queue memory, when the number of queue elements in the queue memory is less than a certain value, the queue memory can be downsized. As an embodiment, the method further comprises:

[0052] Step C10, if Ba<first threshold, the first threshold is greater than Ca / 2 and less than Ca.

[0053] It should be noted that if the first threshold is less than Ca, it indicates that the queue elements in the current queue memory are only stored in the queue main memory. At this time, if the queue auxiliary memory exists, the queue auxiliary memory is in an idle state. At this time, the queue auxiliary memory can be released first to improve the memory utilization.

[0054] Step C20, it is judged whether the queue auxiliary memory currently exists, if yes, step C30 is executed, otherwise, step C40 is executed.

[0055] It should be noted that under the premise of Ba<first threshold, if the queue auxiliary memory does not currently exist, it is further judged whether Ca needs to be reduced.

[0056] Step C30, releasing the queue auxiliary memory.

[0057] Step C40, if Ba< second threshold value, the second threshold value is less than or equal to Ca / 2, performing step C50.

[0058] Step C50, setting Ca= Ca / 2, initializing a new queue main memory with a size of Ca, re-writing data in the original queue main memory into the new queue main memory, and releasing the original queue main memory.

[0059] As a preferred embodiment, the first threshold value is set to 2Ca / 3, and the second threshold value is set to Ca / 3.

[0060] It can be understood that Ca is dynamically adjusted according to the change of Ba, and steps C10-C50 are the process of shrinking the queue memory, and if there is a new element to be inserted into the queue subsequently, the process jumps to step S2 for execution.

[0061] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in the description herein is for describing particular embodiments only and is not intended to be limiting of the application. As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.

[0062] It is to be understood that some of the example embodiments are described in terms of a process or method being performed at a processing system, although such process or method can be embodied in many different ways. Although various steps or operations are described in a particular order, many of the steps or operations can be performed concurrently, in parallel, or in a different order. Additionally, many of the steps or operations can be rearranged, combined, or eliminated without departing from the overall function of the process. The process can be terminated when its operations are completed, but can also have additional steps not included in the figure. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.

[0063] An electronic device is also provided, including at least one processor, and a memory connected with the at least one processor in communication; wherein the memory stores instructions executed by the at least one processor, and the instructions are configured to perform the method described in the embodiments of the application.

[0064] A computer readable storage medium is also provided, storing computer executable instructions, and the computer executable instructions are configured to perform the method described in the embodiments of the application.

[0065] The embodiment of the present application stores queue elements by setting a queue main memory and a queue auxiliary memory, first enables the queue main memory, then enables the queue auxiliary memory, and when the queue main memory and the queue auxiliary memory are insufficient to meet the queue element storage requirement, updates the size of the queue main memory and the queue auxiliary memory to expand, reduces the frequency of queue element copying and memory releasing in the dynamic change process of the single queue, and improves the queue memory utilization rate of the single queue.

[0066] The above is only the preferred embodiment of the present application, and does not limit the present application in any form. Although the present application has been disclosed as above with the preferred embodiment, it is not intended to limit the present application. Any person skilled in the art can make some changes or modifications to the above disclosed technical content to obtain equivalent embodiments with equivalent changes, as long as the changes or modifications do not deviate from the technical solution of the present application. Any simple modification, equivalent change and modification of the above embodiments according to the technical essence of the present application still belong to the scope of the technical solution of the present application.

Claims

1. A dynamic memory management method based on a single queue, characterized in that, Comprising: Step S1, initializing a queue main memory with a size of Ca, setting an initial number of current queue elements Ba=0, the queue being a single-direction queue without a specified container capacity; Step S2, obtaining a queue element to be inserted into the queue, if Ba Step S3, inserting the queue element to be inserted into the queue main memory, setting Ba=Ba+1, and returning to step S2; Step S4, if Ba=Ca, executing step S6, otherwise, executing step S5; Step S5, if Ba=2×Ca, executing step S8, otherwise, executing step S7, Step S6, initializing a queue auxiliary memory with a size of Ca, setting the queue auxiliary memory and the queue main memory as logically continuous queue memories, and executing step S7; Step S7, inserting the queue element to be inserted into the queue auxiliary memory, setting Ba=Ba+1, and returning to step S2; Step S8, setting Ca=2×Ca, initializing a new queue main memory with a size of Ca, re-writing the queue elements in the original queue main memory and the queue auxiliary memory into the new queue main memory, releasing the original queue main memory and the queue auxiliary memory, initializing a new queue auxiliary memory with a size of Ca, inserting the queue element to be inserted into the new queue auxiliary memory, and returning to step S2.

2. The method of claim 1, wherein the queue supports insertion or deletion of a queue element at the tail of the queue, and in step S8, re-writing the queue elements in the original queue main memory and the queue auxiliary memory into the new queue main memory comprises: Step S81, directly concatenating the queue elements in the original queue main memory and the queue auxiliary memory and storing the concatenated queue elements into the new queue main memory.

3. The method of claim 1, wherein the queue main memory comprises Ca memory units, the queue auxiliary memory comprises Ca memory units, the queue elements in the queue, the memory units in the queue main memory, and the memory units in the queue auxiliary memory are sequentially numbered from x, and the method further comprises: Step S10, obtaining a queue element to be accessed queue element label Q, Q being a serial number of the queue element to be accessed in the queue; Step S20, if the queue element to be accessed queue element label is less than or equal to x+Ca-1, executing step S30, otherwise, executing step S40; Step S30, determining the queue element in the memory unit with label Q in the queue main memory as the queue element to be accessed, and returning, ending the access process; Step S40, determining the queue element in the memory unit with label Q-Ca in the queue auxiliary memory as the queue element to be accessed, and returning, ending the access process.

4. The method of claim 1, wherein the method further comprises: Step C00, if a queue element deletion instruction is received, deleting the first queue element at the tail of the queue from the queue memory, and setting Ba=Ba-1.

5. The method of claim 4, wherein the method further comprises: Step C10, if Ba is less than a first threshold, the first threshold being greater than Ca / 2 and less than Ca. ​ ​ ​ ​ Step C20, judging whether there is a queue auxiliary memory currently, if yes, executing step C30, otherwise, executing step C40; Step C30, releasing the queue auxiliary memory; Step C40, if Ba<second threshold value, the second threshold value is less than or equal to Ca / 2, executing step C50; Step C50, setting Ca=Ca / 2, initializing a new queue main memory with the size of Ca, re-writing the data in the original queue main memory into the new queue main memory, and releasing the original queue main memory.

6. The method of claim 5, wherein the first threshold value is set to 2Ca / 3.

7. The method of claim 5, wherein the second threshold value is set to Ca / 3.

8. The method of claim 1, wherein the queue is generated based on a SystemVerilog, C++, Java, Go, or Swift language. comprising: at least one processor; and a memory connected with the at least one processor in communication; 9. An electronic device, comprising: wherein the memory stores instructions executed by the at least one processor, the instructions being configured to perform the method of any one of preceding claims 1-8. computer executable instructions stored in the memory, the computer executable instructions being configured to perform the method of any one of preceding claims 1-8. ​ ​ 10. A computer-readable storage medium, characterized in that, ​

Citation Information

Patent Citations

  • Method and device for data storage

    CN104008067A

  • Queue processing method and device, equipment and storage medium

    CN118245241A