Memory allocation method and system, terminal and storage medium

By configuring the memory pool and using the balanced binary search tree to manage memory blocks, the problem of low data copy efficiency caused by different memory spaces between multiple computing units is solved, and efficient memory utilization and scientific management are achieved.

CN119781979AInactive Publication Date: 2025-04-08山东云泺供应链管理有限公司

Patent Information

Application Number
CN202411955983.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-28
Publication Date
2025-04-08
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the scenario where multiple computing units perform data processing on a service data, since the memory space applied for by each computing unit belongs to a different address space, data copying takes a long time, which reduces the efficiency of the computing unit in the processing of service data.

Method used

By obtaining the data processing flow and memory requirements characteristics, configuring the memory pool, and managing memory blocks based on the balanced binary search tree, using the best adaptation strategy for memory allocation and release, avoiding unnecessary data copying.

Benefits of technology

It realizes precise configuration, efficient utilization and flexible management of memory, improves the scientificity and effectiveness of memory management, avoids memory waste, and ensures the smooth development of data processing work.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781979A_ABST
    Figure CN119781979A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of memory control, and particularly provides a memory allocation method and system, a terminal and a storage medium, and the method comprises the steps: configuring a memory pool based on a data processing flow and memory demand characteristics; obtaining a basic unit of each calculation unit for processing data each time, and configuring an address range and a current state for each memory block based on the determined size of the memory block in the memory pool; constructing a balanced binary search tree, and inserting all the memory blocks into nodes of the balanced binary search tree based on the sizes of the memory blocks; acquiring a memory allocation request, searching an optimal memory block in the balanced binary search tree based on the optimal adaptation strategy for memory allocation, and updating the current state of the optimal memory block to be occupied; and obtaining a memory release request, releasing the corresponding memory block back to the memory pool, and updating the current state of the released memory block to be idle. Accurate configuration, efficient utilization and flexible management of the memory are achieved, and scientificity and effectiveness of memory management are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of memory control technology, and in particular to a memory allocation method, system, terminal and storage medium. Background Art

[0002] Memory is one of the most important components in a computer. It is a bridge for communication with the CPU. All programs in a computer are run in memory, so the performance of memory has a great impact on the computer. Memory is also called internal storage. Its function is to temporarily store the calculation data in the CPU and the data exchanged with external storage such as hard disk. As long as the computer is running, the CPU will transfer the data to be calculated to the memory for calculation. When the calculation is completed, the CPU will transmit the result. The operation of the memory also determines the stable operation of the computer.

[0003] Typically, in a scenario where multiple computing units process data for a business, each computing unit can apply for a memory space from the operating system, so that one computing unit can first process the data and store the processed data in a memory space applied for by the one computing unit. Then, another computing unit can copy the data stored in the one memory space to another memory space applied for by the other computing unit and process the copied data, and so on, until the multiple computing units complete the data processing for the business data.

[0004] However, since the memory space applied for by each of the above-mentioned multiple computing units belongs to a different address space from the memory space applied for by other computing units, each computing unit needs to copy the data obtained after data processing by other computing units to the applied memory space before processing the data. Therefore, each computing unit may need to wait for a long time before it can process the data, which may cause the above-mentioned multiple computing units to need a long time to complete the data processing of the business data, thus resulting in poor efficiency of the computing units in processing the business data. Summary of the invention

[0005] In view of the above-mentioned deficiencies in the prior art, the present invention provides a memory allocation method, system, terminal and storage medium to solve the above-mentioned technical problems.

[0006] In a first aspect, the present invention provides a memory allocation method, comprising the following steps: S1, obtain the data processing flow and memory demand characteristics, and configure the memory pool based on the data processing flow and memory demand characteristics; S2, obtaining the basic unit of each computing unit for processing data each time, determining the size of the memory block in the memory pool based on the basic unit, and configuring the address range and current state for each memory block; S3, build a balanced binary search tree, insert all memory blocks into the nodes of the balanced binary search tree based on the size of the memory blocks, and store the size, address range and current state of the memory blocks in the nodes of the balanced binary search tree; S4, obtain a memory allocation request, and search for the best memory block in the balanced binary search tree based on the best fit strategy for memory allocation, update the current state of the best memory block to occupied and store it in the corresponding node of the balanced binary search tree; S5, obtains a memory release request, releases the corresponding memory block back to the memory pool, updates the current state of the released memory block to free and stores it in the corresponding node of the balanced binary search tree.

[0007] In an optional implementation, step S2 specifically includes: S2-1, take the first inserted memory block as the root node; S2-2, compare the size of the second inserted memory block with the memory block size of the root node. If the size of the second inserted memory block is larger than the memory block size of the root node, the second inserted memory block is the right child node, otherwise it is the left child node; S2-3, continue to insert multiple subsequent memory blocks as the left child node or the right child node, the child node of the left child node, and the child node of the right child node respectively. Each time a memory block is inserted, the left subtree height and the right subtree height of the root node are obtained, and the difference between the left subtree height and the right subtree height is calculated as the balance factor. If the absolute value of the balance factor is not greater than 1, the binary search tree is balanced. If the absolute value of the balance factor is greater than 1, the binary search tree is unbalanced. S2-4, when the binary search tree is unbalanced, adjust the structure of the binary search tree through rotation operations and determine a new root node, and return to S2-3 until the binary search tree is balanced; S2-5, repeat steps S2-3 and S2-4 to complete the insertion of all memory blocks.

[0008] In an optional implementation, a unique number is set for each memory block, and a memory table is constructed based on the number, size, address range and current status of the memory block. The arrangement order in the memory table is based on the continuous order of the address range, and the number of each memory block is also inserted into the corresponding node of the binary search tree.

[0009] In an optional implementation, step S5 specifically includes: Get the number, size and address range of the released memory block; Based on the number of the released memory block, the corresponding address range is searched in the memory table to determine whether the address range of the released memory block is consistent with the address range in the memory table; When the judgment is consistent, update the corresponding current status in the memory table and the balanced binary search tree; When it is determined to be inconsistent, the released memory block is determined to be a fragmented memory block, a fragmented memory table is constructed based on the construction rule of the memory table, a fragment number and a current state related to the corresponding memory block in the memory table are configured for the fragmented memory block, the fragment number, current size, current address range and current state of the fragmented memory block are stored in the fragmented memory table according to the continuous order of the address range, and then the fragment number, size, address range and current state of the fragmented memory block are inserted into the balanced binary search tree.

[0010] In an optional implementation, after the fragment number, current size, current address range and current state of the fragment memory block are stored in the fragment memory table, Obtain the fragment number of the adjacent fragment memory block of the fragment memory block, and determine whether the address range of the adjacent fragment memory block is continuous with the address range of the current fragment memory block; When it is determined to be discontinuous, the fragment number, size, address range and current state of the fragment memory block are stored in the fragment memory table, and the fragment number, size, address range and current state of the fragment memory block are inserted into the balanced binary search tree; When it is determined to be continuous, the two fragmented memory blocks are merged, and the merged memory block is numbered based on the numbering rule of the memory block, the size, address range and current state of the merged memory block are obtained, the corresponding information of the fragmented memory block in the memory table is deleted, the corresponding node of the fragmented memory block in the balanced binary search tree is deleted, and the size, address range and current state of the merged memory block are inserted into the balanced binary search tree.

[0011] In an optional implementation, after merging two fragmented memory blocks, find the original memory blocks corresponding to the two fragmented memory blocks in the memory table, update the address range of the original memory block based on the address range of the fragmented memory block, update the size of the original memory block based on the size of the fragmented memory block, delete the nodes corresponding to the two original memory blocks in the balanced binary search tree, and insert the original memory blocks after updating the size and address range and the merged memory blocks into the balanced binary search tree respectively.

[0012] In an optional implementation, in step S1, a 30% margin is reserved when configuring the memory pool.

[0013] In a second aspect, the present invention provides a memory allocation system, which executes the above-mentioned memory allocation method when implemented, and the system includes: A memory pool configuration module obtains the data processing flow and memory demand characteristics, and configures the memory pool based on the data processing flow and memory demand characteristics; The memory block configuration module obtains the basic unit of each computing unit for processing data each time, determines the size of the memory block in the memory pool based on the basic unit, and configures the address range and current status for each memory block; The memory block sorting module builds a balanced binary search tree, inserts all memory blocks into the nodes of the balanced binary search tree based on the size of the memory blocks, and stores the size, address range and current state of the memory blocks in the nodes of the balanced binary search tree; A memory allocation request module obtains a memory allocation request, searches for the best memory block in the balanced binary search tree based on the best fit strategy for memory allocation, updates the current state of the best memory block to occupied and stores it in the corresponding node of the balanced binary search tree; The memory release request module obtains the memory release request, releases the corresponding memory block back to the memory pool, updates the current state of the released memory block to free and stores it in the corresponding node of the balanced binary search tree.

[0014] In a third aspect, a terminal is provided, including: processor, memory, wherein: The memory is used to store computer programs. The processor is used to call and run the computer program from the memory, so that the terminal executes the above-mentioned terminal method.

[0015] According to a fourth aspect, a computer storage medium is provided, wherein the computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the computer executes the methods described in the above aspects.

[0016] The beneficial effects of the present invention are that the memory allocation method, system, terminal and storage medium provided by the present invention can reasonably configure the memory pool according to the data processing flow and memory demand characteristics, determine the adapted memory block size, address range and status, manage the memory blocks in an orderly manner with the help of a balanced binary search tree, efficiently allocate memory using the best adaptation strategy, and properly handle memory release requests. One memory pool can solve the entire data processing flow, and there is no need to copy data, etc., which realizes the accurate configuration, efficient utilization and flexible management of memory as a whole, effectively improves the scientificity and effectiveness of memory management, avoids memory waste, and ensures the smooth progress of data processing.

[0017] In addition, the invention has a reliable design principle, a simple structure and a very broad application prospect. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0019] Figure 1 It is a schematic flow chart of a memory allocation method according to an embodiment of the present invention.

[0020] Figure 2 It is a schematic block diagram of a memory allocation system according to an embodiment of the present invention.

[0021] Figure 3 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.

[0024] The key terms appearing in the present invention are explained below.

[0025] The memory allocation method provided in the embodiment of the present invention is executed by a computer device, and accordingly, the memory allocation system runs in the computer device.

[0026] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention. Figure 1 The execution subject may be a memory allocation system. According to different requirements, the order of the steps in the flowchart may be changed, and some may be omitted.

[0027] like Figure 1 As shown, the method includes: S1, obtain the data processing flow and memory demand characteristics, and configure the memory pool based on the data processing flow and memory demand characteristics; By deeply understanding the data processing flow and the corresponding memory demand characteristics, you can plan memory resources in a targeted manner in advance. This avoids blind allocation of memory and ensures that the configured memory pool size and attributes match the actual business scenario. This will neither affect data processing efficiency due to insufficient memory nor cause idle resources to be wasted due to excessive memory allocation.

[0028] S2, obtaining the basic unit of each computing unit for processing data each time, determining the size of the memory block in the memory pool based on the basic unit, and configuring the address range and current state for each memory block; Determining the size of the memory block based on the basic unit of data processing by the computing unit can make the granularity of memory allocation more in line with the actual data operation requirements. This means that the amount of memory allocated each time is more accurate, reducing the additional overhead caused by memory blocks that are too large or too small, and improving the efficiency and rationality of memory allocation. Configuring an address range and a clear current status for each memory block makes memory management clear and orderly. You can easily know the usage of each memory block, quickly locate available memory blocks and used memory blocks, and provide accurate basic information for subsequent memory allocation, release and other operations, reducing management complexity.

[0029] S3, build a balanced binary search tree, insert all memory blocks into the nodes of the balanced binary search tree based on the size of the memory blocks, and store the size, address range and current state of the memory blocks in the nodes of the balanced binary search tree; By utilizing the characteristics of a balanced binary search tree, operations such as searching and inserting memory blocks can be implemented with a relatively fast time complexity. Memory blocks are stored in order according to size. When it is necessary to find a suitable memory block for allocation, the eligible memory block can be quickly located, thus improving the speed of memory allocation decision-making.

[0030] S4, obtain a memory allocation request, and search for the best memory block in the balanced binary search tree based on the best fit strategy for memory allocation, update the current state of the best memory block to occupied and store it in the corresponding node of the balanced binary search tree; By adopting the best adaptation strategy, the free memory block closest to the requested size will be selected for allocation as much as possible, reducing the fragmentation problem caused by allocating too large a memory block, so that memory resources can be fully utilized, satisfying more memory allocation requests to the maximum extent, and improving the space utilization of the entire memory pool.

[0031] S5, obtains a memory release request, releases the corresponding memory block back to the memory pool, updates the current state of the released memory block to free and stores it in the corresponding node of the balanced binary search tree.

[0032] It can recycle unused memory blocks in time and return them to the scope of allocatable resources in the memory pool, providing available memory for subsequent memory allocation requests, realizing the recycling of memory resources and avoiding resource waste such as memory leaks.

[0033] Optionally, as an embodiment of the present invention, the size of the business data and the processing mode of each computing unit on the data are obtained. It is necessary to clarify whether each processing step will change the data size, for example, encryption may not change the data size, while format conversion may change the data size.

[0034] Observe the memory usage of each computing unit during data processing. Is it reading all the data at once for processing, or processing in small batches (such as reading 1MB each time). Some computing units may need additional memory to store intermediate results or temporary data, which should be taken into account. For example, the data analysis computing unit may need to create some temporary data structures to store statistical information, and this part of the memory demand also needs to be counted.

[0035] If each computing unit requires a complete copy of the data, the memory pool size must be at least equal to the business data size multiplied by the number of computing units. In order to cope with possible fluctuations in memory demand, such as temporary data peaks, memory usage of the operating system or other software, a 20%-50% margin should be reserved based on the calculated basic memory demand. In this embodiment, 30% is used.

[0036] During data processing, there are many small memory requests (such as less than 1MB) and a small number of large memory requests (such as greater than 10MB). The memory pool is divided into multiple mixed-size memory blocks using multiples of the basic unit. That is, when the basic unit is 1MB, a part of the memory is divided into small blocks (such as 1MB) and a part of the memory is divided into large blocks (such as 10MB) to meet different needs. In this way, while meeting small memory requests, large memory requests can also be effectively processed, reducing the generation of memory fragmentation.

[0037] Optionally, as an embodiment of the present invention, step S2 specifically includes: S2-1, take the first inserted memory block as the root node; S2-2, compare the size of the second inserted memory block with the memory block size of the root node. If the size of the second inserted memory block is larger than the memory block size of the root node, the second inserted memory block is the right child node, otherwise it is the left child node; S2-3, continue to insert multiple subsequent memory blocks as the left child node or the right child node, the child node of the left child node, and the child node of the right child node respectively. Each time a memory block is inserted, the left subtree height and the right subtree height of the root node are obtained, and the difference between the left subtree height and the right subtree height is calculated as the balance factor. If the absolute value of the balance factor is not greater than 1, the binary search tree is balanced. If the absolute value of the balance factor is greater than 1, the binary search tree is unbalanced. S2-4, when the binary search tree is unbalanced, adjust the structure of the binary search tree through rotation operations and determine a new root node, and return to S2-3 until the binary search tree is balanced; S2-5, repeat steps S2-3 and S2-4 to complete the insertion of all memory blocks.

[0038] Since each insertion requires a balance judgment (balance factor = left subtree height - right subtree height), the imbalance of the balance factor can be divided into the following four types: Left-left imbalance: The balance factor is 2, and the balance factor of the left child node is 1. In this case, a right rotation operation is required to restore the balance. For example, assuming that the balance factor of node A is 2, and the balance factor of its left child node B is 1, the right rotation operation will promote B to the new root node, A becomes the right child node of B, and adjust their subtree relationship to rebalance the tree.

[0039] Right-right imbalance: The balance factor is -2, and the balance factor of the right child node is -1. In this case, a left rotation operation is required to promote the right child node to the new root node, and the original root node becomes the left child node of the new root node, while adjusting the subtree relationship.

[0040] Left-right imbalance: The balance factor is 2, and the balance factor of the left child node is -1. This situation is more complicated, and you need to first perform a left rotation operation on the left child node, and then perform a right rotation operation on the current node to restore the balance.

[0041] Right-left imbalance: The balance factor is -2, and the balance factor of the right child node is 1. It is also necessary to perform a right rotation operation first, and then a left rotation operation to adjust the tree structure.

[0042] Optionally, as an embodiment of the present invention, a unique number is set for each memory block, and a memory table is constructed based on the number, size, address range and current status of the memory block. The arrangement order in the memory table is based on the continuous order of the address range, and the number of each memory block is also inserted into the corresponding node of the binary search tree.

[0043] Optionally, as an embodiment of the present invention, step S5 specifically includes: Get the number, size and address range of the released memory block; Based on the number of the released memory block, the corresponding address range is searched in the memory table to determine whether the address range of the released memory block is consistent with the address range in the memory table; When it is determined to be consistent, the corresponding current status in the memory table and the balanced binary search tree is updated; in the memory table, the status of the memory block is marked as "free" to indicate that the memory block can be reused for subsequent memory allocation requests. At the same time, in the balanced binary search tree, the current status information of the memory block stored in the corresponding node is also updated to "free". Through this synchronous update, the memory block information recorded in different data structures of the memory management system is always consistent, which facilitates the acquisition of accurate real-time status information when performing memory search, allocation and other operations based on these structures.

[0044] When it is determined to be inconsistent, the released memory block is determined to be a fragmented memory block, and a fragmented memory table is constructed based on the construction rules of the memory table, because the inconsistent address range means that the situation of the memory block does not meet the expectations of a normal complete memory block, and it is likely to be in an irregular state due to reasons such as memory fragmentation. At this time, a special fragmented memory table is constructed based on the construction rules of the memory table in order to manage these fragmented memory blocks separately and in an orderly manner.

[0045] The fragmented memory block is configured with a fragment number and current status related to the corresponding memory block in the memory table, and the fragment number, current size, current address range and current status of the fragmented memory block are stored in the fragmented memory table according to the continuous order of the address range. The fragment number and current status related to the corresponding memory block in the memory table are configured for the fragmented memory block, wherein the fragment number is used to uniquely identify the fragmented memory block in the fragmented memory table, which is convenient for subsequent search, management and other operations. Then, in the continuous order of the address range, the fragment number, current size, current address range and current status of the fragmented memory block are stored in the fragmented memory table. This order arrangement is similar to the memory table based on the continuous order of the address range, which helps to intuitively display the distribution of the fragmented memory in the memory space, and facilitates the subsequent search for adjacent fragmented memory blocks for possible merging and other operations.

[0046] The fragment number, size, address range and current state of the fragmented memory block are inserted into the balanced binary search tree, so that the balanced binary search tree can also effectively manage the fragmented memory block.

[0047] Optionally, as an embodiment of the present invention, after the fragment number, current size, current address range and current state of the fragment memory block are stored in the fragment memory table, Obtain the fragment number of the adjacent fragment memory block of the fragment memory block, and determine whether the address range of the adjacent fragment memory block is continuous with the address range of the current fragment memory block; When it is judged to be discontinuous, it means that these fragmented memory blocks cannot be directly merged to form a larger continuous available memory space. The fragment number, size, address range and current status of the fragmented memory block are stored in the fragmented memory table to ensure that its information can be accurately saved for reference in subsequent possible memory allocation operations. The fragment number, size, address range and current status of the fragmented memory block are inserted into the balanced binary search tree, so that when looking for a suitable memory block (including fragmented memory blocks) for allocation, the fragmented memory block can be quickly located through the balanced binary search tree, so that it can participate in the allocation process of memory resources in the form of independent fragments, ensuring the effective management of discontinuous fragmented memory blocks; When it is determined to be continuous, the two fragmented memory blocks are merged, that is, they are integrated into a continuous memory block in the physical memory space, so that it can serve as a larger available memory resource to meet the subsequent larger memory allocation requests that may appear. And the merged memory block is numbered based on the numbering rule of the memory block, and a new unique identifier is given to it to facilitate its identification and management in the entire memory management system. The size, address range and current status of the merged memory block are obtained, and then the relevant data structures involved in memory management need to be adjusted accordingly, the corresponding information of the fragmented memory block in the memory table is deleted, the corresponding node of the fragmented memory block in the balanced binary search tree is deleted, and the size, address range and current status of the merged memory block are inserted into the balanced binary search tree.

[0048] The specific steps to delete a node include: Starting from the root node of the balanced binary search tree, compare the value of the node to be deleted (here, the memory block related attributes, such as size, number, etc., used for comparison) with the value of the current node. If the value of the node to be deleted is less than the value of the current node, recursively search the left subtree; if it is greater than the value of the current node, recursively search the right subtree. Until the node to be deleted is found or the leaf node is reached (indicating that the node to be deleted is not found).

[0049] If the node to be deleted is a leaf node, just delete the node directly. Then start from the parent node of the node and check the balance of the tree upwards, because deleting the leaf node may cause the balance of the tree to be destroyed. When the node to be deleted has only one child node, replace its position with the child node of the node. When deleting a node with two child nodes, first find the in-order successor (the node with the smallest value in its right subtree) or in-order predecessor (the node with the largest value in its left subtree) of the node to be deleted. Taking the in-order successor as an example, assuming that the node to be deleted is N, find the node M with the smallest value in the right subtree of N. Copy the value of M to N, and then delete M. Since M is the smallest node in the right subtree, M has at most one right child node (it may have no child nodes). At this time, it becomes the previous two cases (deleting leaf nodes or nodes with only one child node) to handle the deletion of M.

[0050] After deleting a node, it is necessary to update the heights of all ancestor nodes from the deleted node position upwards, and recalculate and judge the balance factor.

[0051] Optionally, as an embodiment of the present invention, after two fragmented memory blocks are merged, the original memory blocks corresponding to the two fragmented memory blocks are found in the memory table. After the two fragmented memory blocks are merged, the reason why their original memory blocks corresponding to the two fragmented memory blocks are found in the memory table is that these fragmented memory blocks were originally generated by splitting some complete memory blocks.

[0052] The merged fragmented memory blocks form a new continuous memory area. The range change of this area will affect the distribution description of the original memory blocks related to it in the memory space. Therefore, the address range of the original memory blocks is updated based on the address range of the fragmented memory blocks, and the size of the original memory blocks is updated based on the size of the fragmented memory blocks.

[0053] In order to ensure that the information in the balanced binary search tree is consistent with the memory table and the actual memory status, the nodes corresponding to the two original memory blocks are deleted from the balanced binary search tree respectively, and the original memory blocks and the merged memory blocks after updating the size and address range are inserted into the balanced binary search tree respectively.

[0054] Through the above series of operations, after the fragmented memory blocks are merged, the information of key data structures such as memory tables and balanced binary search trees involved in the memory management system can be fully and accurately updated to ensure that the status information of memory resources is real-time and accurate, further improving the efficiency of memory management and the overall utilization level of memory resources.

[0055] In some embodiments, the memory allocation system may include a plurality of functional modules composed of computer program segments. The computer programs of the various program segments in the memory allocation system may be stored in a memory of a computer device and executed by at least one processor to perform (see Figure 1 Description) Memory allocation function.

[0056] In this embodiment, the memory allocation system can be divided into multiple functional modules according to the functions it performs, such as Figure 2 As shown. The functional modules of the system 200 may include: a memory pool configuration module, a memory block configuration module, a memory block sorting module, a memory allocation request module, and a memory release request module. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments. The system includes: A memory pool configuration module obtains the data processing flow and memory demand characteristics, and configures the memory pool based on the data processing flow and memory demand characteristics; The memory block configuration module obtains the basic unit of each computing unit for processing data each time, determines the size of the memory block in the memory pool based on the basic unit, and configures the address range and current status for each memory block; The memory block sorting module builds a balanced binary search tree, inserts all memory blocks into the nodes of the balanced binary search tree based on the size of the memory blocks, and stores the size, address range and current state of the memory blocks in the nodes of the balanced binary search tree; A memory allocation request module obtains a memory allocation request, searches for the best memory block in the balanced binary search tree based on the best fit strategy for memory allocation, updates the current state of the best memory block to occupied and stores it in the corresponding node of the balanced binary search tree; The memory release request module obtains the memory release request, releases the corresponding memory block back to the memory pool, updates the current state of the released memory block to free and stores it in the corresponding node of the balanced binary search tree.

[0057] Several modules work together to reasonably configure the memory pool according to the data processing flow and memory demand characteristics, accurately determine the memory block size, address range and status, efficiently sort and manage memory blocks with the help of a balanced binary search tree, and use the best adaptation strategy to achieve scientific memory allocation. At the same time, it properly handles memory release operations, effectively improving the scientificity, accuracy and efficiency of memory management, ensuring the rational use of memory resources, and laying a solid foundation for the smooth development of related data processing work.

[0058] Figure 3A schematic diagram of the structure of a terminal provided in an embodiment of the present invention. The terminal can be used to execute the memory allocation method provided in an embodiment of the present invention.

[0059] The terminal may include: a processor, a memory and a communication unit. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention. It may be a bus structure or a star structure, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0060] The memory can be used to store the execution instructions of the processor, and the memory can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. When the execution instructions in the memory are executed by the processor, the terminal is enabled to execute some or all of the steps in the following method embodiments.

[0061] The processor is the control center of the storage terminal, which uses various interfaces and lines to connect various parts of the entire electronic terminal, and executes various functions and / or processes data of the electronic terminal by running or executing software programs and / or modules stored in the memory, and calling data stored in the memory. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor can only include a central processing unit (CPU). In the embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.

[0062] The communication unit is used to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals or send user data to other terminals.

[0063] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).

[0064] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes, including several instructions for enabling a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention.

[0065] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.

[0066] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, which can be electrical, mechanical or other forms.

[0067] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0068] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0069] Although the present invention has been described in detail with reference to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person of ordinary skill in the art may easily think of changes or substitutions within the technical scope disclosed by the present invention, and these shall be within the scope of protection of the present invention.

Claims

1. A memory allocation method, characterized in that: The following steps are involved: S1, obtain the data processing flow and memory demand characteristics, and configure the memory pool based on the data processing flow and memory demand characteristics; S2, obtaining the basic unit of each computing unit for processing data each time, determining the size of the memory block in the memory pool based on the basic unit, and configuring the address range and current state for each memory block; S3, build a balanced binary search tree, insert all memory blocks into the nodes of the balanced binary search tree based on the size of the memory blocks, and store the size, address range and current state of the memory blocks in the nodes of the balanced binary search tree; S4, obtain a memory allocation request, and search for the best memory block in the balanced binary search tree based on the best fit strategy for memory allocation, update the current state of the best memory block to occupied and store it in the corresponding node of the balanced binary search tree; S5, obtains a memory release request, releases the corresponding memory block back to the memory pool, updates the current state of the released memory block to free and stores it in the corresponding node of the balanced binary search tree.

2. The memory allocation method according to claim 1, characterized in that: Step S2 specifically includes: S2-1, take the first inserted memory block as the root node; S2-2, compare the size of the second inserted memory block with the memory block size of the root node. If the size of the second inserted memory block is larger than the memory block size of the root node, the second inserted memory block is the right child node, otherwise it is the left child node; S2-3, continue to insert multiple subsequent memory blocks as the left child node or the right child node, the child node of the left child node, and the child node of the right child node respectively. Each time a memory block is inserted, the left subtree height and the right subtree height of the root node are obtained, and the difference between the left subtree height and the right subtree height is calculated as the balance factor. If the absolute value of the balance factor is not greater than 1, the binary search tree is balanced. If the absolute value of the balance factor is greater than 1, the binary search tree is unbalanced. S2-4, when the binary search tree is unbalanced, adjust the structure of the binary search tree through rotation operations and determine a new root node, and return to S2-3 until the binary search tree is balanced; S2-5, repeat steps S2-3 and S2-4 to complete the insertion of all memory blocks.

3. The memory allocation method according to claim 2, characterized in that: A unique number is set for each memory block, and a memory table is constructed based on the number, size, address range and current status of the memory block. The arrangement order in the memory table is based on the continuous order of the address range, and the number of each memory block is also inserted into the corresponding node of the binary search tree.

4. The memory allocation method according to claim 3, characterized in that: Step S5 specifically includes: Get the number, size and address range of the released memory block; Based on the number of the released memory block, the corresponding address range is searched in the memory table to determine whether the address range of the released memory block is consistent with the address range in the memory table; When the judgment is consistent, update the corresponding current status in the memory table and the balanced binary search tree; When it is determined to be inconsistent, the released memory block is determined to be a fragmented memory block, a fragmented memory table is constructed based on the construction rule of the memory table, a fragment number and a current state related to the corresponding memory block in the memory table are configured for the fragmented memory block, the fragment number, current size, current address range and current state of the fragmented memory block are stored in the fragmented memory table according to the continuous order of the address range, and then the fragment number, size, address range and current state of the fragmented memory block are inserted into the balanced binary search tree.

5. The memory allocation method according to claim 4, characterized in that: After storing the fragment number, current size, current address range, and current status of the fragment memory block in the fragment memory table, Obtain the fragment number of the adjacent fragment memory block of the fragment memory block, and determine whether the address range of the adjacent fragment memory block is continuous with the address range of the current fragment memory block; When it is determined to be discontinuous, the fragment number, size, address range and current state of the fragment memory block are stored in the fragment memory table, and the fragment number, size, address range and current state of the fragment memory block are inserted into the balanced binary search tree; When it is determined to be continuous, the two fragmented memory blocks are merged, and the merged memory block is numbered based on the numbering rule of the memory block, the size, address range and current state of the merged memory block are obtained, the corresponding information of the fragmented memory block in the memory table is deleted, the corresponding node of the fragmented memory block in the balanced binary search tree is deleted, and the size, address range and current state of the merged memory block are inserted into the balanced binary search tree.

6. The memory allocation method according to claim 5, characterized in that: After merging the two fragmented memory blocks, find the original memory blocks corresponding to the two fragmented memory blocks in the memory table, update the address range of the original memory block based on the address range of the fragmented memory block, update the size of the original memory block based on the size of the fragmented memory block, delete the nodes corresponding to the two original memory blocks in the balanced binary search tree, and insert the original memory blocks after updating the size and address range and the merged memory blocks into the balanced binary search tree respectively.

7. The memory allocation method according to claim 1, characterized in that: In step S1, the memory pool reserves 30% of the margin when configuring.

8. A memory allocation system, characterized in that: When the system is implemented, the memory allocation method according to any one of claims 1 to 7 is executed, and the system includes: A memory pool configuration module obtains the data processing flow and memory demand characteristics, and configures the memory pool based on the data processing flow and memory demand characteristics; The memory block configuration module obtains the basic unit of each computing unit for processing data each time, determines the size of the memory block in the memory pool based on the basic unit, and configures the address range and current status for each memory block; The memory block sorting module builds a balanced binary search tree, inserts all memory blocks into the nodes of the balanced binary search tree based on the size of the memory blocks, and stores the size, address range and current state of the memory blocks in the nodes of the balanced binary search tree; A memory allocation request module obtains a memory allocation request, searches for the best memory block in the balanced binary search tree based on the best fit strategy for memory allocation, updates the current state of the best memory block to occupied and stores it in the corresponding node of the balanced binary search tree; The memory release request module obtains the memory release request, releases the corresponding memory block back to the memory pool, updates the current state of the released memory block to free and stores it in the corresponding node of the balanced binary search tree.

9. A terminal, characterized in that: include: A memory for storing a memory allocation program; A processor, used to implement the steps of the memory allocation method as described in any one of claims 1-7 when executing the memory allocation program.

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

Citation Information

Patent Citations

  • Memory algorithm facing real-time system

    CN102880555A

  • Strictly balanced binary tree dynamic processing method and device, storage medium and device

    CN111026765A

  • Storage space management method and apparatus

    WO2016187974A1

Cited By

  • Memory management method, device and equipment, storage medium and computer program product

    CN120407204A

  • AVL tree rapid data retrieval method based on distributed access unit

    CN121070927A