Memory management method, apparatus, device, and medium

By creating multiple temporary registers during program initialization and allocating memory blocks through these registers at runtime, the problems of low memory utilization and poor performance under the immediate allocation strategy are solved, achieving more efficient memory management and performance improvement.

CN120973506AActive Publication Date: 2025-11-18JOINT WARFARE COLLEGE NAT DEFENSE UNIV OF THE CHINESE PEOPLES LIBERATION ARMY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510813187.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-17
Publication Date
2025-11-18
Estimated Expiration
2045-06-17

AI Technical Summary

Technical Problem

Existing on-demand allocation strategies result in low memory utilization and poor system performance when processing large-scale data. Frequent memory allocation and deallocation operations increase management complexity and performance overhead.

Method used

During program initialization, register initialization parameters are predefined. Multiple registers are created by requesting memory space at once, and memory blocks are allocated through registers at runtime. This reduces the number of times the operating system is directly called to allocate memory, and the multi-level register strategy balances access speed and storage capacity.

Benefits of technology

It improves memory utilization efficiency and program performance, reduces the performance overhead of memory management, simplifies the memory management process, and reduces memory fragmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973506A_ABST
    Figure CN120973506A_ABST
Patent Text Reader

Abstract

The application discloses a memory management method, device, equipment and medium. The method comprises the following steps: obtaining pre-defined temporary register initialization parameters during initialization; applying memory space to an operating system once according to the temporary register initialization parameters, and obtaining initialized temporary registers; obtaining a first value corresponding to memory application of a target application program during running of the target application program; traversing all the initialized temporary registers, and calculating a difference value between a memory space value corresponding to at least one memory block in each temporary register and the first value; searching for an optimal temporary register in all the temporary registers according to the difference value; when the optimal temporary register is found, allocating at least one memory block in an unused state from the optimal temporary register to the target application program, and marking a state of each allocated memory block as a used state. The method can uniformly allocate and manage memory blocks by creating temporary registers in advance, reduce the number of times of directly calling system memory allocation, and improve memory use efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a memory management method, apparatus, device, and medium. Background Technology

[0002] On-demand allocation is a memory management strategy that refers to dynamically requesting and allocating memory based on actual needs during program runtime. The program only requests memory when it is actually needed, thus avoiding the occupation of large amounts of unused memory resources at program startup. Because memory is allocated on demand during runtime, the program can dynamically adjust its memory usage according to actual running conditions and workload, allowing it to better adapt to different operating environments and conditions.

[0003] However, the just-in-time allocation strategy also has its potential challenges and problems. For example, each memory request requires an allocation operation, which incurs overhead, especially when processing large-scale data. Frequent memory allocation and deallocation operations can lead to significant performance overhead. This is because each memory allocation or deallocation requires management work, such as updating memory management data structures. Frequent memory operations can cause frequent cache invalidation, increasing the number of times data is read from main memory, resulting in poor system performance. Secondly, for large-scale data processing, it is difficult to predict the exact memory requirements of the program at runtime. While the just-in-time allocation strategy can allocate memory on demand, improper management can easily lead to frequent memory allocation and deallocation, increasing the complexity of memory management and resulting in low memory utilization.

[0004] Therefore, there is an urgent need to propose a memory management method to solve the above problems. Summary of the Invention

[0005] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a memory management method, apparatus, device and medium to solve the problem that existing memory management methods cannot meet efficiency requirements during large-scale data processing, resulting in poor memory utilization and overall system performance.

[0006] In a first aspect, embodiments of the present invention provide a memory management method, the method comprising: during initialization, obtaining predefined temporary register initialization parameters, the temporary register initialization parameters including a memory space configuration value, an initial number of memory blocks, and a number of temporary registers, the memory space configuration value being used to configure the memory space value corresponding to a single memory block within a temporary register, the initial number of memory blocks being used to configure the number of memory blocks contained in a single temporary register, and the number of temporary registers being used to configure the total number of temporary registers of the same level to be created; requesting memory space from the operating system at once according to the temporary register initialization parameters, obtaining each initialized temporary register; during the runtime of the target application, obtaining a first value corresponding to the memory requested by the target application; traversing all initialized temporary registers, calculating the difference between the memory space value corresponding to at least one memory block within each temporary register and the first value; searching for the optimal temporary register among all temporary registers based on the difference, the optimal temporary register being the one with the smallest difference among all temporary registers; when the optimal temporary register is found, directly allocating at least one unused memory block from the optimal temporary register to the target application, and marking the state of each allocated memory block as used.

[0007] Secondly, embodiments of the present invention also provide a memory management device, comprising: an initialization parameter acquisition module configured to acquire predefined temporary register initialization parameters during initialization, the temporary register initialization parameters including a memory space configuration value, an initial memory block count, and a temporary register count, wherein the memory space configuration value is used to configure the memory space value corresponding to a single memory block within a temporary register, the initial memory block count is used to configure the number of memory blocks contained in a single temporary register, and the temporary register count is used to configure the total number of temporary registers of the same level to be created; and an initialization memory allocation module configured to request memory space from the operating system at once according to the temporary register initialization parameters, thereby obtaining each initialized temporary register; and a target request module; The memory acquisition module is configured to acquire the first value corresponding to the memory requested by the target application when the target application runs; the difference calculation module is configured to traverse all initialized registers and calculate the difference between the memory space value corresponding to at least one memory block in each register and the first value; the optimal register search module is configured to search for the optimal register among all registers based on the difference, and the optimal register is the register with the smallest difference among all registers; the first memory allocation module is configured to allocate at least one unused memory block from the optimal register to the target application when the optimal register is found, and mark the status of each allocated memory block as used.

[0008] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the embodiments of the present invention.

[0009] Fourthly, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in the embodiments of the present invention.

[0010] The beneficial effects of the technical solution provided by this invention are:

[0011] This invention provides a memory management method, apparatus, device, and medium. During initialization, the method obtains predefined temporary register initialization parameters, including a memory space configuration value, an initial number of memory blocks, and a number of temporary registers. The memory space configuration value is used to configure the memory space value corresponding to a single memory block within a temporary register. The initial number of memory blocks is used to configure the number of memory blocks contained in a single temporary register. The number of temporary registers is used to configure the total number of temporary registers of the same level to be created. Based on the temporary register initialization parameters, memory space is requested from the operating system in one go, resulting in initialized temporary registers. Then, during the target application's runtime, a first value corresponding to the memory requested by the target application is obtained. All initialized temporary registers are traversed, and the difference between the memory space value corresponding to at least one memory block within each temporary register and the first value is calculated. Based on the difference, the optimal temporary register is found among all temporary registers; the optimal temporary register is the one with the smallest difference among all temporary registers. Finally, upon finding the optimal temporary register, at least one unused memory block is directly allocated from it to the target application, and the status of each allocated memory block is marked as used. By pre-creating multiple temporary registers during program initialization and pre-allocating memory space to them, and then allocating memory blocks through these registers during program runtime, the number of direct calls to the operating system for memory allocation is reduced, as is the performance overhead of calling allocation functions, thereby improving memory utilization efficiency and program performance. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 A flowchart illustrating a memory management method proposed in some embodiments of the present invention is shown;

[0014] Figure 2 A flowchart illustrating a memory management method according to some embodiments of the present invention is shown;

[0015] Figure 3A flowchart illustrating a memory management method provided in some other embodiments of the present invention is shown;

[0016] Figure 4 A schematic diagram showing the distribution of memory blocks within each temporary register provided in an embodiment of the present invention is shown;

[0017] Figure 5 A schematic diagram illustrating the memory allocation and memory release process provided in an embodiment of the present invention is shown;

[0018] Figure 6 The diagram shows a schematic representation of the structure of a memory management device provided in some embodiments of the present invention;

[0019] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present invention is shown. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not intended to limit the invention. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.

[0021] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0022] To better understand the inventive concept provided by this invention, the following is combined with... Figure 1-7 The memory management method proposed in this invention will be described in detail.

[0023] Please refer to Figure 1 , Figure 1 A flowchart illustrating a memory management method according to some embodiments of the present invention is shown. This method can be implemented by a memory management device configured in an electronic device. The method includes:

[0024] Step 101: During initialization, obtain the predefined temporary register initialization parameters. The temporary register initialization parameters include the memory space configuration value, the initial number of memory blocks, and the number of temporary registers. The memory space configuration value is used to configure the memory space value corresponding to a single memory block in the temporary register. The initial number of memory blocks is used to configure the number of memory blocks contained in a single temporary register. The number of temporary registers is used to configure the total number of temporary registers of the same level to be created.

[0025] Step 102: Request memory space from the operating system all at once according to the temporary register initialization parameters to obtain each initialized temporary register.

[0026] Step 103: When the target application is running, obtain the first value corresponding to the memory requested by the target application.

[0027] Step 104: Traverse all initialized temporary registers and calculate the difference between the memory space value corresponding to at least one memory block in each temporary register and the first value.

[0028] Step 105: Find the optimal temporary register among all temporary registers based on the difference. The optimal temporary register is the one with the smallest difference among all temporary registers.

[0029] Step 106: When the optimal temporary register is found, at least one unused memory block is directly allocated from the optimal temporary register to the target application, and the status of each allocated memory block is marked as used.

[0030] In the above steps, during program initialization, a pre-allocated memory space of a preset size is requested all at once. Predefined temporary register initialization parameters are used to create the temporary registers. For example, temporary register initialization parameters can be defined as follows:

[0031]

[0032] Obtaining predefined register initialization parameters may involve reading a configuration file containing the original register initialization parameters; validating the original register initialization parameters to obtain valid ones, which are then used as the predefined register initialization parameters. The number of registers is a value between 1 and 16. The validity of the register number setting is determined by validating the register number parameter value in the configuration file. The size of a single register memory block is the configured memory space value for a single memory block, such as 1024, 2048, or 4096 bytes. The required memory space for the registers is calculated based on the single memory block size and the number of registers. If this exceeds 3 / 4 of the total operating system memory, the register initialization parameters in the configuration file are unreasonable, requiring adjustment of the single memory block size and the number of registers. The user is prompted with a configuration problem, or a new configuration file needs to be reloaded. If the requirement does not exceed this, the register initialization parameters in the configuration file are reasonable, and subsequent pre-allocation processing continues.

[0033] The system requests memory space from the operating system in one go based on the register initialization parameters, resulting in initialized registers. The register initialization parameters include multiple memory space configuration values, a corresponding initial memory block count, and a corresponding number of registers. These multiple memory space configuration values ​​include first-level, second-level, and third-level values. The process of requesting memory space from the operating system in one go based on these parameters results in initialized registers. This includes creating and initializing registers based on the first-level value, the corresponding initial memory block count, and the corresponding number of registers, resulting in a first register; creating and initializing registers based on the second-level value, the corresponding initial memory block count, and the corresponding number of registers, resulting in a second register; and creating and initializing registers based on the third-level value, the corresponding initial memory block count, and the corresponding number of registers, resulting in a third register.

[0034] In some embodiments, creating and initializing a temporary register may include: determining that the temporary register to be created is the current temporary register; creating a stack structure corresponding to the current temporary register, the stack structure being used to manage the memory blocks contained in the current temporary register, the stack structure being encapsulated by a linked list data structure, each element in the stack structure being the memory space value allocated to a single memory block contained in the current temporary register; requesting memory space corresponding to the memory space configuration value from the operating system according to the memory space configuration value, obtaining the memory space value corresponding to a single memory block of the current temporary register; using the memory space value corresponding to a single memory block as a new element of the stack structure and performing a push operation to complete the initialization of the current temporary register; after each push operation, updating the cumulative value of the new elements pushed onto the stack until the cumulative value is equal to the initial number of memory blocks corresponding to the current temporary register, thus obtaining a first temporary register, a second temporary register, or a third temporary register.

[0035] When the memory space configuration value is at the first level, the system requests memory space corresponding to the first level value from the operating system, obtaining the memory space value corresponding to a single memory block of the current temporary register. Alternatively, when the memory space configuration value is at the second level, the system requests memory space corresponding to the second level value from the operating system, obtaining the memory space value corresponding to a single memory block of the current temporary register. Or, when the memory space configuration value is at the third level, the system requests memory space corresponding to the third level value from the operating system, obtaining the memory space value corresponding to a single memory block of the current temporary register. After obtaining the memory space value corresponding to a single memory block of the current temporary register, the memory space value corresponding to the single memory block is used as a new element of the stack structure, and a push operation is performed to complete the initialization of the current temporary register. Different temporary registers have different stack structures. A push operation is performed for each stack structure until the cumulative value of the new elements pushed onto the stack equals the number of initial memory blocks corresponding to the current temporary register, resulting in a first temporary register corresponding to the first level value, a second temporary register corresponding to the second level value, or a third temporary register corresponding to the third level value.

[0036] For example, memory pre-allocation can be achieved using the following pseudocode:

[0037]

[0038]

[0039] The above process enables memory pre-allocation. After pre-allocation, when the target application runs, it needs to request memory based on its memory requirements. This is achieved by iterating through all initialized temporary registers and calculating the difference between the memory space value corresponding to at least one memory block in each register and a first value. Based on this difference, the optimal temporary register is searched among all registers. When the optimal temporary register is found, at least one unused memory block is directly allocated from it to the target application, and the status of each allocated memory block is marked as used. The first value is the target memory request size. Based on this target memory request size, the most suitable temporary register is searched for, and memory is allocated to the target application by that register. Figure 4 As shown, Figure 4This diagram illustrates the distribution of memory blocks within various temporary registers provided in this embodiment of the invention. Based on hierarchical temporary registers, such as L1, L2, and L3 registers, each level has different capacity and access speed. The L1 register has the fastest access speed but the smallest capacity; the L3 register has a relatively slower access speed but a larger capacity. By introducing a multi-level storage strategy, data of different sizes is stored in different storage areas, which can balance access speed and storage capacity, effectively improving memory utilization efficiency. Specifically, the L1 register is the first temporary register, the L2 register is the second temporary register, and the L3 register is the third temporary register.

[0040] The memory management method provided in this invention pre-creates multiple temporary registers during program initialization and pre-allocates memory space to the temporary registers. During program execution, memory blocks are then allocated through the temporary registers. This reduces the number of times the operating system is directly called to allocate memory and reduces the performance overhead caused by calling the allocation function, thereby improving memory utilization efficiency and program performance.

[0041] Please refer to Figure 2 , Figure 2 A flowchart illustrating a memory management method according to further embodiments of the present invention is shown. This method can be implemented by a memory management device configured in an electronic device. The method includes:

[0042] Step 201: During initialization, obtain the predefined temporary register initialization parameters. The temporary register initialization parameters include the memory space configuration value, the initial number of memory blocks, and the number of temporary registers. The memory space configuration value is used to configure the memory space value corresponding to a single memory block in the temporary register. The initial number of memory blocks is used to configure the number of memory blocks contained in a single temporary register. The number of temporary registers is used to configure the total number of temporary registers of the same level to be created.

[0043] Step 202: Request memory space from the operating system all at once according to the temporary register initialization parameters to obtain each initialized temporary register.

[0044] Step 203: When the target application is running, obtain the first value corresponding to the memory requested by the target application.

[0045] Step 204: Traverse all initialized registers and calculate the difference between the memory space value corresponding to at least one memory block in each register and the first value.

[0046] Step 205: Find the optimal temporary register among all temporary registers based on the difference. The optimal temporary register is the one with the smallest difference among all temporary registers.

[0047] Step 206: When the optimal temporary register is found, at least one unused memory block is directly allocated from the optimal temporary register to the target application, and the status of each allocated memory block is marked as used.

[0048] Step 207: If the optimal temporary register cannot be found, the operating system's predefined memory allocation function is directly called to allocate memory space corresponding to the first value to the target application.

[0049] In the above steps, if an optimal temporary register cannot be found, the operating system's predefined memory allocation function is directly called to allocate memory space corresponding to the first value to the target application. The first value is the amount of memory requested by the target application from the operating system.

[0050] After pre-allocating memory blocks to temporary registers, when the program needs to request memory at runtime, a suitable temporary register is found based on the difference between the requested memory size and at least one memory block in the temporary register. Then, memory is allocated using the optimal temporary register.

[0051] In some embodiments, the method further includes acquiring the memory block to be freed when memory needs to be freed. If it is determined that the memory block to be freed was allocated by calling the operating system's memory allocation function, then the memory block is freed by calling a predefined memory release function of the operating system. If it is determined that the memory block to be freed was allocated from a temporary register, then the memory block is placed back into the data structure used to manage memory blocks, and the memory block is marked as unused. The data structure used to manage memory blocks corresponds to the temporary register that allocated the memory block to be freed.

[0052] When memory needs to be freed, it should be released. For example, when a program terminates, all allocated memory resources will be automatically reclaimed by the operating system. Alternatively, when a dynamically allocated data structure (such as a linked list, tree, etc.) is no longer in use, its occupied memory resources should be released back to the operating system.

[0053] Because memory allocation can involve both temporary registers and operating system memory allocation functions, memory release requires identification of the memory block. If the memory block to be released was allocated using the operating system's memory allocation function, then the operating system's predefined memory release function is invoked to release the memory block. If the memory block to be released was allocated using a temporary register, then the memory block is placed back into the data structure used to manage memory blocks and marked as unused. This data structure corresponds to the temporary register that allocated the memory block. For example, this data structure could be a stack.

[0054] When freeing up memory, the following pseudocode can be used:

[0055]

[0056] The memory management method provided in this invention is compatible with allocating memory using temporary registers and allocating memory by calling predefined memory allocation functions of the operating system. When releasing memory, it also identifies the memory allocation strategy, which can better manage memory resources, reduce memory fragmentation, and improve memory utilization efficiency.

[0057] Please refer to Figure 3 , Figure 3 A flowchart illustrating a memory management method according to other embodiments of the present invention is shown. This method can be implemented by a memory management device configured in an electronic device. After memory allocation is completed, the method includes:

[0058] Step 301: Based on the comparison between the second value of the memory blocks in the optimal temporary register that are in use and the preset percentage threshold of the total number of memory blocks in the optimal temporary register, determine whether it is necessary to expand the capacity of the optimal temporary register; if necessary, proceed to step 302, otherwise proceed to step 307.

[0059] Step 302: When the second value of the memory blocks in the optimal temporary register that are in use reaches a preset percentage threshold of the total number of memory blocks in the optimal temporary register, it is determined that the optimal temporary register needs to be expanded.

[0060] Step 303: Calculate the product of the initial number of memory blocks corresponding to the optimal temporary register and the preset third value, which is used as the new number of memory blocks to be updated in the optimal temporary register.

[0061] Step 304: Compare the number of new memory blocks with the maximum memory space allowed by the optimal temporary register to obtain the comparison result.

[0062] Step 305: If the comparison result indicates that the number of new memory blocks exceeds the maximum memory space value allowed by the optimal temporary register, no update operation is performed on the number of initial memory blocks corresponding to the optimal temporary register, indicating that the expansion has failed.

[0063] Step 306: If the comparison result indicates that the number of new memory blocks does not exceed the maximum memory space value allowed by the optimal temporary register, the initial number of memory blocks corresponding to the optimal temporary register is updated to the new number of memory blocks, indicating that the expansion is successful.

[0064] Step 307: If the second value of the memory blocks in the optimal temporary register that are in use does not reach the preset percentage threshold of the total number of memory blocks in the optimal temporary register, it is determined that the optimal temporary register does not need to be expanded.

[0065] In the above steps, based on the relationship between the second value of the memory blocks in the optimal temporary register that are in use and the preset percentage threshold of the total number of memory blocks in the optimal temporary register, it can be determined whether the current optimal temporary register needs to be expanded. Here, the second value is the number of memory blocks in the current optimal temporary register that are in use. The preset percentage threshold can be, for example, 3 / 4. Assuming the initial number of memory blocks in the current optimal temporary register is 200, and the initial number of memory blocks is the total number of memory blocks in the current optimal temporary register, if the second value of the memory blocks in the current optimal temporary register that are in use reaches the preset percentage threshold of the total number of memory blocks in the optimal temporary register, it is determined that the optimal temporary register needs to be expanded. For example, if the second value is 180, the total number of memory blocks in the optimal temporary register is 200, and the preset percentage threshold is 3 / 4, then 180 is greater than 200*(3 / 4), indicating that the current optimal temporary register needs to be expanded. If the second value of the memory blocks currently in use within the optimal temporary register does not reach the preset percentage threshold of the total number of memory blocks in the optimal temporary register, then it is determined that the optimal temporary register does not need to be expanded. Figure 5 As shown, Figure 5 This diagram illustrates the memory allocation and deallocation process provided in an embodiment of the present invention. During memory allocation, the optimal temporary register is searched to determine whether memory should be allocated through the register or by calling the operating system's memory allocation function. If the optimal temporary register is found, memory is allocated using it, and the memory block is marked as in use. If no optimal temporary register is found, the operating system's memory allocation function is called to allocate memory. When allocating memory through the optimal temporary register, it can be further determined whether the register needs to be expanded. If expansion is required, it is further determined whether the expanded memory exceeds the maximum memory limit of the optimal temporary register. If it does, expansion cannot be performed; otherwise, expansion is performed, and memory allocation is considered successful.

[0066] When releasing memory, it is determined whether the memory was allocated by a temporary register. If so, the memory block is marked as unused and returned to the temporary register. If not, the operating system's memory release function is called to release the memory block, thus successfully releasing the memory.

[0067] The new memory block count to be updated in the optimal register can be calculated by multiplying the initial memory block count corresponding to the optimal register by a third value. This third value could be, for example, 1.5 times the initial memory block count. Taking the initial memory block count of the optimal register as 200 as an example, 200 * 1.5 = 300. If the current optimal register modifies the memory block count to 300, which is less than or equal to the maximum allowed memory value, then the expansion is successful. If the current optimal register modifies the memory block count to 300, which is greater than the maximum allowed memory value, then the expansion fails, and the memory block count of the current optimal register is not modified.

[0068] When allocating memory, the following pseudocode can be used:

[0069]

[0070]

[0071] The memory management method provided in this invention monitors the usage of memory blocks in real time when requesting memory, and determines whether the temporary register needs to be expanded based on the usage of memory blocks. This ensures that the program uses memory as efficiently as possible during operation, and allocates and releases memory resources reasonably, reducing the number of memory allocation and release operations, while also simplifying the memory management process.

[0072] Please refer to Figure 6 , Figure 6 A schematic diagram of a memory management device provided in some embodiments of the present invention is shown. This device can be configured in an electronic device and includes:

[0073] The initialization parameter acquisition module 601 is configured to acquire predefined temporary register initialization parameters during initialization. The temporary register initialization parameters include memory space configuration value, initial memory block number, and number of temporary registers. The memory space configuration value is used to configure the memory space value corresponding to a single memory block in the temporary register. The initial memory block number is used to configure the number of memory blocks contained in a single temporary register. The number of temporary registers is used to configure the total number of temporary registers of the same level to be created.

[0074] The initialization memory allocation module 602 is configured to request memory space from the operating system all at once according to the temporary register initialization parameters, and obtain each initialized temporary register.

[0075] The target memory request module 603 is configured to obtain the first value corresponding to the memory requested by the target application when the target application is running.

[0076] The difference calculation module 604 is configured to traverse all initialized temporary registers and calculate the difference between the memory space value corresponding to at least one memory block in each temporary register and the first value.

[0077] The optimal register lookup module 605 is configured to find the optimal register among all registers based on the difference, whereby the optimal register is the register with the smallest difference among all registers.

[0078] The first memory allocation module 606 is configured to allocate at least one unused memory block directly from the optimal temporary register to the target application when the optimal temporary register is found, and to mark the status of each allocated memory block as used.

[0079] In some embodiments, the device further includes a second memory allocation module, configured to directly call a memory allocation function predefined by the operating system to allocate memory space corresponding to the first value to the target application when no optimal temporary register can be found.

[0080] In some embodiments, the register initialization parameters include multiple memory space configuration values, an initial number of memory blocks corresponding to each memory space configuration value, and a number of registers corresponding to each memory space configuration value. The multiple memory space configuration values ​​include a first-level value, a second-level value, and a third-level value. The memory allocation module 602 is configured to: create and initialize registers according to the first-level value, the initial number of memory blocks corresponding to the first-level value, and the number of registers corresponding to the first-level value, to obtain a first register; create and initialize registers according to the second-level value, the initial number of memory blocks corresponding to the second-level value, and the number of registers corresponding to the second-level value, to obtain a second register; and create and initialize registers according to the third-level value, the initial number of memory blocks corresponding to the third-level value, and the number of registers corresponding to the third-level value, to obtain a third register.

[0081] In some embodiments, the initialization memory allocation module 602 is configured to determine the temporary register to be created as the current temporary register; create a stack structure corresponding to the current temporary register, the stack structure is used to manage the memory blocks contained in the current temporary register, the stack structure is encapsulated by a linked list data structure, and each element in the stack structure is the memory space value allocated to a single memory block contained in the current temporary register; request memory space corresponding to the memory space configuration value from the operating system according to the memory space configuration value, and obtain the memory space value corresponding to a single memory block of the current temporary register; use the memory space value corresponding to the single memory block as a new element of the stack structure and perform a push operation to complete the initialization of the current temporary register; after each push operation, update the cumulative value of the new elements pushed onto the stack until the cumulative value is equal to the initial number of memory blocks corresponding to the current temporary register, and obtain the first temporary register, the second temporary register, or the third temporary register.

[0082] In some embodiments, the device further includes a register expansion module, which is configured to: determine that the optimal register needs to be expanded when the second value of the memory blocks in the optimal register that are in a used state reaches a preset percentage threshold of the total number of memory blocks in the optimal register; or determine that the optimal register does not need to be expanded when the second value of the memory blocks in the optimal register that are in a used state does not reach the preset percentage threshold of the total number of memory blocks in the optimal register.

[0083] In some embodiments, the register expansion module is configured to calculate the product of the initial memory block count corresponding to the optimal register and a preset third value, as the new memory block count to be updated in the optimal register; if it is determined that the new memory block count exceeds the maximum memory space value allowed by the optimal register, the expansion fails, and no update operation is performed on the initial memory block count corresponding to the optimal register; or, if it is determined that the new memory block count does not exceed the maximum memory space value allowed by the optimal register, the expansion succeeds; and the initial memory block count corresponding to the optimal register is updated to the new memory block count.

[0084] In some embodiments, the device further includes a memory release module, which is configured to, when memory needs to be released, acquire a memory block to be released; if it is determined that the memory block to be released was allocated by calling the operating system's memory allocation function, then call the operating system's predefined memory release function to release the memory block; or, if it is determined that the memory block to be released was allocated by a temporary register, then put the memory block back into the data structure used to manage memory blocks and mark the memory block as unused, wherein the data structure used to manage memory blocks corresponds to the temporary register that allocated the memory block to be released.

[0085] The memory management device provided in this embodiment of the invention pre-creates multiple temporary registers during program initialization and pre-allocates memory space to the temporary registers. During program execution, memory blocks are then allocated through the temporary registers. This reduces the number of times the operating system is directly called to allocate memory and reduces the performance overhead caused by calling the allocation function, thereby improving memory utilization efficiency and program performance.

[0086] Furthermore, by monitoring the usage of memory blocks in real time when requesting memory, and determining whether temporary storage needs to be expanded based on the memory block usage, the program can ensure that it uses memory as efficiently as possible during operation, allocates and releases memory resources reasonably, reduces the number of memory allocation and release operations, and simplifies the memory management process.

[0087] Furthermore, it is compatible with allocating memory using temporary registers and calling predefined memory allocation functions of the operating system. When releasing memory, it can also better manage memory resources, reduce memory fragmentation, and improve memory utilization efficiency by recognizing the memory allocation strategy.

[0088] The following is for reference. Figure 7 , Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present invention is shown. This electronic device may be a computer electronic device. Figure 7 It does not impose limitations on the structure of electronic devices. For example... Figure 7 As shown, the electronic device includes at least a memory 701 and a processor 702. For example, the electronic device may also include... Figure 7 Showing more or fewer components (such as network interfaces, display devices, etc.).

[0089] In particular, according to the embodiments provided by the present invention, the above refers to the flowchart. Figure 1-3 The described process can be implemented as a computer software program. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a machine-readable medium, the computer program containing program code for performing the methods shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), it performs the functions defined in the system of the present invention.

[0090] It should be noted that the computer-readable medium disclosed herein may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0091] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of the methods and computer program products described according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, program segment, or portion of code, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0092] The units or modules described in the embodiments provided by this invention can be implemented in software or hardware. The described units or modules can also be located in a processor. For example, a processor can be described as including an initialization parameter acquisition module, an initialization memory allocation module, a target memory allocation module, a difference calculation module, an optimal temporary register lookup module, and a first memory allocation module. The names of these units or modules do not necessarily limit the unit or module itself; for example, the initialization parameter acquisition module can also be described as "a module used to acquire predefined temporary register initialization parameters during initialization."

[0093] In another aspect, this invention also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The computer-readable storage medium stores one or more programs that are used by one or more processors to execute the memory management method described in this invention.

[0094] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention is not limited to the specific combination of the above-described technical features, but also includes other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in this invention.

Claims

1. A memory management method, characterized in that, The method includes: During initialization, predefined temporary register initialization parameters are obtained. These parameters include memory space configuration values, initial memory block count, and number of temporary registers. The memory space configuration values ​​are used to configure the memory space value corresponding to a single memory block within a temporary register. The initial memory block count is used to configure the number of memory blocks contained in a single temporary register. The number of temporary registers is used to configure the total number of temporary registers of the same level to be created. The system requests memory space from the operating system in one go according to the temporary register initialization parameters, and obtains each initialized temporary register. When the target application is running, obtain the first value corresponding to the memory requested by the target application; Iterate through all initialized registers and calculate the difference between the memory space value corresponding to at least one memory block in each register and the first value. Based on the difference, the optimal register is found among all registers, and the optimal register is the register with the smallest difference among all registers. When the optimal temporary register is found, at least one unused memory block is directly allocated from the optimal temporary register to the target application, and the status of each allocated memory block is marked as used.

2. The method according to claim 1, characterized in that, The method also includes: If the optimal temporary register cannot be found, the operating system's predefined memory allocation function is directly invoked to allocate memory space corresponding to the first value to the target application.

3. The method according to claim 1 or 2, characterized in that, The temporary register initialization parameters include multiple memory space configuration values, an initial memory block quantity corresponding to each memory space configuration value, and a temporary register quantity corresponding to each memory space configuration value. The multiple memory space configuration values ​​include a first-level value, a second-level value, and a third-level value. Based on the temporary register initialization parameters, memory space is requested from the operating system in a single request to obtain initialized temporary registers, including: Based on the first level value, the number of initial memory blocks corresponding to the first level value, and the number of temporary registers corresponding to the first level value, a temporary register is created and initialized to obtain the first temporary register. Based on the second level value, the number of initial memory blocks corresponding to the second level value, and the number of temporary registers corresponding to the second level value, create and initialize temporary registers to obtain the second temporary register; Based on the third level value, the number of initial memory blocks corresponding to the third level value, and the number of temporary registers corresponding to the third level value, a temporary register is created and initialized to obtain the third temporary register.

4. The method according to claim 3, characterized in that, The creation and initialization of the temporary register includes: Determine the temporary register to be created as the current temporary register; Create a stack structure corresponding to the current temporary register. The stack structure is used to manage the memory blocks contained in the current temporary register. The stack structure is encapsulated by a linked list data structure. Each element in the stack structure is the memory space value allocated to a single memory block contained in the current temporary register. Based on the memory space configuration value, request memory space from the operating system corresponding to the memory space configuration value, and obtain the memory space value corresponding to a single memory block of the current temporary register; The memory space value corresponding to a single memory block is used as a new element of the stack structure, and a push operation is performed to complete the initialization of the current temporary register. After each push operation, the cumulative value of the new element pushed onto the stack is updated until the cumulative value is equal to the number of initial memory blocks corresponding to the current temporary register, thus obtaining the first temporary register, the second temporary register, or the third temporary register.

5. The method according to claim 1 or 2, characterized in that, The method also includes: When the second value of the memory blocks in the optimal temporary register that are in use reaches a preset percentage threshold of the total number of memory blocks in the optimal temporary register, it is determined that the optimal temporary register needs to be expanded. or, If the second value of the memory blocks in the optimal temporary register that are in use does not reach a preset percentage threshold of the total number of memory blocks in the optimal temporary register, it is determined that the optimal temporary register does not need to be expanded.

6. The method according to claim 5, characterized in that, After determining that the optimal temporary register needs to be expanded, the method includes: Calculate the product of the initial number of memory blocks corresponding to the optimal temporary register and the preset third value, which is the new number of memory blocks to be updated in the optimal temporary register. If the number of new memory blocks exceeds the maximum memory space allowed by the optimal temporary register, no update operation is performed on the initial number of memory blocks corresponding to the optimal temporary register, indicating that the expansion has failed; or... When it is determined that the number of new memory blocks does not exceed the maximum memory space value allowed by the optimal temporary register, the number of initial memory blocks corresponding to the optimal temporary register is updated to the number of new memory blocks, indicating that the expansion is successful.

7. The method according to claim 1, characterized in that, The method also includes: When memory needs to be freed, acquire the memory block to be freed; If it is determined that the memory block to be released was allocated by calling the operating system's memory allocation function, then the memory block is released by calling the operating system's predefined memory release function. or, If it is determined that the memory block to be released was allocated by a temporary register, then the memory block is put back into the data structure used to manage memory blocks and the memory block is marked as unused. The data structure used to manage memory blocks corresponds to the temporary register that allocated the memory block to be released.

8. A memory management device, characterized in that, The device includes: The initialization parameter acquisition module is configured to acquire predefined temporary register initialization parameters during initialization. The temporary register initialization parameters include memory space configuration value, initial memory block number, and number of temporary registers. The memory space configuration value is used to configure the memory space value corresponding to a single memory block in the temporary register. The initial memory block number is used to configure the number of memory blocks contained in a single temporary register. The number of temporary registers is used to configure the total number of temporary registers of the same level to be created. The initialization memory allocation module is configured to request memory space from the operating system all at once according to the temporary register initialization parameters, thereby obtaining each initialized temporary register. The target memory request module is configured to obtain the first value corresponding to the memory requested by the target application when the target application is running; The difference calculation module is configured to traverse all initialized temporary registers and calculate the difference between the memory space value corresponding to at least one memory block in each temporary register and the first value. The optimal register lookup module is configured to find the optimal register among all registers based on the difference, wherein the optimal register is the register with the smallest difference among all registers. The first memory allocation module is configured to, when the optimal temporary register is found, directly allocate at least one unused memory block from the optimal temporary register to the target application, and mark the status of each allocated memory block as used.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any one of claims 1-7.