A memory allocation method, system, electronic device and storage medium

By generating and filtering multiple initial memory allocation policies, determining the best policy and allocating memory resources for the software modules of embedded devices, the problems of low memory allocation efficiency and insurmountable policy rationality are solved, and more efficient memory utilization and device performance improvement are achieved.

CN119883653BActive Publication Date: 2025-06-20SHANDONG YUNHAI GUOCHUANG CLOUD COMPUTING EQUIP IND INNOVATION CENT CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510362118.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-26
Publication Date
2025-06-20
Estimated Expiration
2045-03-26

AI Technical Summary

Technical Problem

In the prior art, the memory allocation efficiency of embedded devices is low, and the rationality of the memory allocation strategy cannot be guaranteed, especially when the functional modules are added and the data scale is expanded.

Method used

By obtaining the memory allocation restrictions of embedded devices, multiple initial memory allocation policies are generated, and the optimal memory allocation strategy is determined according to the preset filter conditions, and finally allocating memory resources to each software module according to the best strategy.

Benefits of technology

It realizes more efficient memory allocation, ensures the rationality of memory allocation strategies, and improves the overall performance and memory resource utilization of embedded devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883653B_ABST
    Figure CN119883653B_ABST
Patent Text Reader

Abstract

The present application discloses a memory allocation method, system, electronic device and storage medium, relating to the field of computer technology. After obtaining the memory allocation limit conditions of the embedded device, a variety of initial memory allocation strategies are generated, and the best strategy is determined according to the preset screening conditions. This not only fully considers the memory requirements and limiting factors of each software module, but also realizes the automatic screening of the best strategy, improving the memory allocation efficiency while ensuring the rationality of the memory allocation strategy, laying a foundation for improving the overall performance and memory resource utilization rate of the embedded device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a memory allocation method, system, electronic device, and storage medium. Background Art

[0002] Currently, embedded devices are widely used in many fields. Affected by the application scenarios of embedded devices, their memory is restricted by various factors. Therefore, how to reasonably allocate memory for embedded devices has become a key issue in the development of embedded devices.

[0003] In related technologies, memory allocation strategies for embedded devices are usually formulated by manual and exhaustive methods. However, with the increase in the number of functional modules and the expansion of data scale of embedded devices, the use of manual and exhaustive methods reduces the memory allocation efficiency, and the rationality of the memory allocation strategy cannot be guaranteed. Summary of the Invention

[0004] This application provides a memory allocation method, system, electronic device, and storage medium to at least solve the problem in related technologies that the memory allocation efficiency is reduced and the rationality of the memory allocation strategy cannot be guaranteed.

[0005] This application provides a memory allocation method, including:

[0006] Obtaining memory allocation constraint conditions of the embedded device;

[0007] Generating multiple initial memory allocation strategies according to the memory allocation constraint conditions;

[0008] Determining the optimal memory allocation strategy according to the multiple initial memory allocation strategies according to a preset memory allocation screening condition;

[0009] Allocating memory resources to each software module in the embedded device according to the optimal memory allocation strategy.

[0010] This application also provides a memory allocation device, including:

[0011] An obtaining module, configured to obtain memory allocation constraint conditions of the embedded device;

[0012] A generating module, configured to generate multiple initial memory allocation strategies according to the memory allocation constraint conditions;

[0013] A determining module, configured to determine the optimal memory allocation strategy according to the multiple initial memory allocation strategies according to a preset memory allocation screening condition;

[0014] An allocating module, configured to allocate memory resources to each software module in the embedded device according to the optimal memory allocation strategy.

[0015] The present application also provides a memory allocation system, including: an embedded device and a memory allocation device, where the embedded device includes multiple software modules;

[0016] The memory allocation device is used to determine the optimal memory allocation strategy by adopting any of the above memory allocation methods and generate a firmware file for the embedded device;

[0017] The embedded device is used to load the firmware file to perform corresponding memory resource allocation for each software module.

[0018] The present application also provides an electronic device, including: a memory for storing a computer program; a processor for implementing the steps of any of the above memory allocation methods when executing the computer program.

[0019] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above memory allocation methods are implemented.

[0020] The present application also provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of any of the above memory allocation methods are implemented.

[0021] Through the present application, after obtaining the memory allocation restriction conditions of the embedded device, multiple initial memory allocation strategies are generated, and the optimal strategy is determined according to the preset screening conditions. This not only fully considers the memory requirements and limiting factors of each software module but also realizes the automatic screening of the optimal strategy, improving the memory allocation efficiency while ensuring the rationality of the memory allocation strategy, laying a foundation for improving the overall performance and memory resource utilization rate of the embedded device. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] To more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0023] Figure 1 It is a schematic flowchart of the memory allocation method provided by the embodiment of the present application;

[0024] Figure 2 It is a schematic structural diagram of the memory allocation diagram provided by the embodiment of the present application;

[0025] Figure 3 It is a schematic overall flowchart of the memory allocation method provided by the embodiment of the present application;

[0026] Figure 4Structural schematic diagram of the memory allocation device provided by the embodiment of the present application;

[0027] Figure 5 Structural schematic diagram of the memory allocation system provided by the embodiment of the present application;

[0028] Figure 6 Structural schematic diagram of the electronic device provided by the embodiment of the present application. Detailed implementation manners

[0029] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.

[0030] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or device including a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0031] As a widely used computer device, the memory allocation of embedded devices is restricted for the following reasons:

[0032] Cost limitation: Embedded devices often need to control costs to meet the requirements of mass production and the consumer market.

[0033] Power consumption limitation: The size and type of memory will affect the power consumption of the device. In battery-powered or low-power devices, smaller memory helps reduce energy consumption.

[0034] Space limitation: Many embedded devices are small in size and limited in space, so a compact hardware design, including memory, is required.

[0035] Performance requirements: Embedded devices usually perform specific tasks and do not require as much memory as general-purpose computers.

[0036] Real-time performance: Some embedded systems need to respond quickly. Using smaller memory can reduce access latency and improve the real-time performance of the system.

[0037] Specialty: Embedded systems are often optimized for specific applications, so only enough memory is needed to meet these specific requirements.

[0038] Due to these limitations, designers of embedded systems need to carefully manage memory resources. In embedded devices, there are many scenarios of static memory usage. The size and location of this static memory are generally specified during the firmware code writing process and will not change during use. If this part of the static memory is allocated reasonably, it is crucial for embedded devices. Reasonable static memory allocation can greatly reduce costs. However, static memory allocation essentially belongs to the bin-packing problem, which has been proven to be an NP-complete problem, meaning that there is no known polynomial-time algorithm that can accurately solve all instances. Generally, there are the following ways of static memory allocation:

[0039] Developers allocate manually. In this way, every time the memory layout changes, manual allocation is required, which is time-consuming and laborious and prone to errors. If there is an overlap in memory allocation, problems such as stepping on memory may occur, and it is difficult to locate.

[0040] Use dynamic programming to exhaust all solutions, which consumes a lot of time and increases sharply as the data scale expands. For scenarios with time requirements, dynamic programming is not suitable at this time.

[0041] Among them, NP-complete problems are an important concept in computational complexity theory. NP stands for "Non-deterministic Polynomial time", and "Complete" means that such problems are representative among NP problems, that is, they are the most difficult NP problems. If any NP problem can be reduced to a specific NP-complete problem in polynomial time, then this problem is NP-complete.

[0042] Embodiments of this application provide a memory allocation method, system, electronic device, and storage medium to solve the above technical problems. The method includes: obtaining memory allocation constraint conditions of an embedded device; generating multiple initial memory allocation strategies according to the memory allocation constraint conditions; determining the optimal memory allocation strategy according to the multiple initial memory allocation strategies according to a preset memory allocation screening condition; and allocating memory resources to each software module in the embedded device according to the optimal memory allocation strategy. The method provided by the above solution, after obtaining the memory allocation constraint conditions of the embedded device, generates multiple initial memory allocation strategies and determines the optimal strategy according to the preset screening conditions, not only fully considers the memory requirements and constraint factors of each software module, but also realizes the automatic screening of the optimal strategy, improving the memory allocation efficiency while ensuring the rationality of the memory allocation strategy, laying a foundation for improving the overall performance and memory resource utilization rate of the embedded device.

[0043] To enable those skilled in the art of this technology to better understand the solution of this application, the following further detailed description of this application will be given in conjunction with the accompanying drawings and specific implementation manners.

[0044] The embodiment of this application provides a memory allocation method, which is used to formulate a memory allocation strategy for an embedded device during the development process of the embedded device. The execution subject of the embodiment of this application is an electronic device, such as a server, a desktop computer, a laptop computer, a tablet computer, and other electronic devices that can be used to generate a memory allocation strategy for an embedded device.

[0045] As Figure 1 shown, it is a schematic flowchart of the memory allocation method provided by the embodiment of this application, and this method includes:

[0046] Step 101, obtain the memory allocation limit conditions of the embedded device.

[0047] Among them, the memory allocation limit conditions are divided into two parts: memory allocation requirement information and memory allocation constraint information. The embedded device includes multiple software modules. The memory allocation requirement information includes the memory size of each software module, and the memory allocation constraint information includes the memory attribute, memory alignment requirement, and the belonging memory pool of each software module, that is, the memory allocation limit conditions at least include the memory size, memory attribute, memory alignment requirement, and the belonging memory pool of each software module. Among them, the software modules include functional modules such as a user registration module and a display module.

[0048] Specifically, the user can fill in the static memory configuration table of the embedded device offline. The static memory configuration table includes, but is not limited to, the name of the software module, the module memory size (occupied static memory size), and the module memory allocation constraint information (memory attribute, alignment requirement, and specified memory pool). An exemplary static memory configuration table is shown in Table 1 below:

[0049] Table 1

[0050]

[0051] Specifically, the memory allocation limit conditions of the embedded device can be determined by analyzing the static memory configuration table filled in by the user offline.

[0052] Step 102, generate multiple initial memory allocation strategies according to the memory allocation limit conditions.

[0053] Among them, any initial memory allocation strategy includes the memory allocation results of each software module. Since the static memory resources of the embedded device are limited, in the embodiments of the present application, first, according to the memory allocation restriction conditions, multiple initial memory allocation strategies that can be satisfied under the limited static memory resources are generated. Taking an embedded device including four software modules A, B, C, and D as an example, any initial memory allocation strategy includes the memory allocation results of the four software modules A, B, C, and D.

[0054] Specifically, in one embodiment, the memory allocation targets of each software module in the embedded device can be determined according to the memory allocation restriction conditions; and multiple initial memory allocation strategies can be generated according to the memory allocation targets of each software module.

[0055] Among them, the memory allocation target of a single software module is the information of one row entry in Table 1 above, that is, the memory allocation target includes memory size, memory attribute, memory alignment requirement, and the memory pool to which it belongs.

[0056] Specifically, after clarifying the memory allocation restriction conditions, a memory allocation plan can be planned for each software module based on these conditions. By trying different memory allocation combinations, multiple initial memory allocation strategies are generated. Each strategy includes the memory allocation results of each software module, that is, it determines how much memory each module obtains from which memory pool. For example, one strategy can give priority to satisfying the modules with high speed requirements, and allocate a high-speed memory pool to the modules with high speed requirements, while another strategy can first satisfy the modules with large memory requirements. Through diverse allocation combinations, more choices are provided for screening out the best strategy later.

[0057] Step 103, according to multiple initial memory allocation strategies, determine the best memory allocation strategy according to the preset memory allocation screening conditions.

[0058] It should be noted that the preset memory allocation screening conditions are the criteria for evaluating and selecting the optimal memory allocation scheme.

[0059] Specifically, from the multiple initial memory allocation strategies generated, with the goal of improving memory utilization and reducing the memory fragmentation rate, the best memory allocation strategy can be determined.

[0060] Step 104, allocate memory resources to each software module in the embedded device according to the best memory allocation strategy.

[0061] Specifically, after determining the best memory allocation strategy, apply it to the embedded device. The embedded device allocates corresponding memory resources (static memory) to each software module according to the best memory allocation strategy, so that each module runs in its allocated memory space.

[0062] Based on the above embodiments, as an implementable manner, in one embodiment, according to preset memory allocation screening conditions and various initial memory allocation strategies, a best memory allocation strategy is determined, including:

[0063] Step 1031: Generate a memory allocation graph according to various initial memory allocation strategies; wherein, the memory allocation graph includes multiple nodes, each node represents the memory allocation result of a single software module, and the memory allocation result includes the memory allocation information of the software module in any memory pool;

[0064] Step 1032: Search for the optimal path on the memory allocation graph according to the preset memory allocation screening conditions;

[0065] Step 1033: Determine the best memory allocation strategy according to the node information included in the optimal path.

[0066] Exemplarily, as Figure 2 shown, it is a schematic structural diagram of the memory allocation graph provided by the embodiments of the present application. The memory allocation graph presents different initial memory allocation strategies in a graphical manner. Figure 2 The memory allocation graph shown is actually a state transition graph of memory allocation, which shows different possibilities and path relationships of software module memory allocation. Among them, represents 4 memory pools, and these 4 memory pools include memory pools of various memory attribute types, such as memory pools of SRAM type and DDR type, etc. 、 and represent 3 memory states, that is, the superscript represents the current memory pool state after the next-level state transition. For example, represents the memory state (remaining memory resources) when the memory pool allocates memory for module A, represents the memory state when the memory pool has allocated memory resources for module A and then allocates memory for module B, and so on. In the figure, module A, module B, and module C are divided, indicating the memory allocation situations for different software modules. Each module has multiple selectable memory allocation nodes, representing that each module has multiple possible memory allocation methods. The connections between the nodes represent memory allocation paths, and different connection combinations constitute different memory allocation strategy paths, which can be used to screen the best memory allocation scheme later.

[0067] Among them, when selecting the optimal path, it is restricted by the following constraint conditions:

[0068] Constraint 1: If the path is , and passes through module m, then , and it is required that , otherwise this path is invalid, which ensures that there is enough remaining memory resources after allocation to avoid negative memory amounts.

[0069] Constraint 2: If the path is , during the state transition process, it is necessary to ensure that the corresponding allocated memory attributes meet the requirements, that is, to ensure that the allocated memory resources have the characteristics required for the operation of software modules, such as read / write speed, cache characteristics, etc.

[0070] Constraint 3: If the path is , during the state transition process, it is necessary to ensure that the allocated address alignment meets the requirements to ensure the correctness and efficiency of data storage and access.

[0071] Constraint 4: Path migration , it is necessary to ensure that this path meets the specified requirements of the corresponding module memory pool. For example, some modules can only obtain memory resources from a specific memory pool, which limits the optional range of memory allocation.

[0072] Specifically, by screening based on the graphical memory allocation diagram, the comparison of complex memory allocation schemes becomes intuitive and efficient, reducing human errors and uncertainties in the screening process; finding the optimal path according to the preset memory allocation screening conditions can maximize the memory utilization rate, reduce the memory fragmentation rate, optimize the memory usage efficiency of embedded devices, thereby improving the overall performance of the device and ensuring that each software module can run stably and efficiently under the reasonably allocated memory resources.

[0073] Specifically, in one embodiment, the path selection evaluation function can be determined according to the preset memory allocation screening conditions; based on the path selection evaluation function, the optimal path is found on the memory allocation diagram.

[0074] It should be noted that the preset memory allocation screening conditions are standards set based on the goals and requirements of memory allocation, such as improving the memory utilization rate, reducing the memory fragmentation rate, meeting the requirements of each software module for memory attributes and alignment, etc. The path selection evaluation function quantifies these conditions into computable mathematical expressions for subsequent evaluation and selection of the optimal path.

[0075] Specifically, the memory allocation graph shows various combinatorial possibilities of memory allocation for different software modules, and each path represents a memory allocation strategy. After determining the path selection evaluation function, each path in the graph is calculated to obtain an evaluation value. This evaluation value reflects the degree to which the memory allocation strategy represented by the path meets the preset screening conditions. By comparing the evaluation values of all paths, the path with the optimal value (such as the maximum or minimum) is the optimal path. The memory allocation method corresponding to the optimal path is the solution that can best meet the memory allocation requirements of the embedded device under the current preset conditions, and can achieve efficient utilization and reasonable allocation of memory resources.

[0076] Specifically, in one embodiment, at least one node can be selected as the starting node on the memory allocation graph; based on the path selection evaluation function, calculate the selection evaluation value of the path between the starting node and the candidate nodes other than the starting node in the memory allocation graph; according to the selection evaluation values of each path, determine the target path and the next node of the starting node; wherein, the next node is connected to the starting node through the target path; take the next node as the new starting node, and return to the step of calculating the selection evaluation value of the path between the starting node and the candidate nodes other than the starting node in the memory allocation graph based on the path selection evaluation function until the destination node is determined to obtain the optimal path of the memory allocation graph.

[0077] Specifically, after selecting the starting node, based on the path selection evaluation function, calculate the selection evaluation value of the path between the starting node and other candidate nodes. The path selection evaluation function synthesizes the pheromone concentration and the heuristic factor, that is, the evaluation function comprehensively considers various factors of memory allocation, such as memory utilization rate and memory fragmentation rate, etc. Determine the target path and the next node of the starting node according to the selection evaluation values of each path, that is, guide the memory allocation to a better direction. Take the next node as the new starting node, and repeat the above calculation and selection process until the destination node is determined.

[0078] Specifically, in one embodiment, for any candidate node, based on the path selection evaluation function, determine the memory utilization rate and memory fragmentation rate of the embedded device according to the memory allocation result jointly represented by the starting node and the candidate node; obtain the selection evaluation mark value of the path between the starting node and the candidate node; according to the selection evaluation mark value, the memory utilization rate and memory fragmentation rate of the embedded device, determine the selection evaluation value of the path between the starting node and the candidate node.

[0079] Among them, the selection evaluation value is positively correlated with the memory utilization rate, and the selection evaluation value is negatively correlated with the memory fragmentation rate.

[0080] Specifically, the starting node represents the current memory allocation state of a certain software module, for example Figure 2 in , The candidate node represents the memory allocation status that can be obtained by other software modules. The combination of these two nodes jointly presents the memory allocation changes. By analyzing the memory usage after such changes, the memory utilization rate and memory fragmentation rate of the embedded device can be determined. The memory utilization rate is the ratio of the used memory to the total memory, reflecting the degree of memory utilization, and the memory fragmentation rate is the proportion of small memory blocks in the memory that cannot be effectively utilized, reflecting the degree of memory fragmentation. These two metrics are important bases for measuring the quality of the memory allocation scheme.

[0081] Among them, the selected evaluation marker value is a record and identification of the path between the starting node and the candidate node, and it is related to the previous evaluation of this path. It can reflect some characteristics or trends of this path in previous evaluations and provide a reference for the current evaluation. Considering the selected evaluation marker value, memory utilization rate, and memory fragmentation rate comprehensively, the selection evaluation value of the path between the starting node and the candidate node is finally determined. Generally, the higher the memory utilization rate and the lower the memory fragmentation rate, the greater the promotion effect on the selection evaluation value. At the same time, the selected evaluation marker value will also affect the final evaluation value according to the set rules. The obtained selection evaluation value can be used to compare the advantages and disadvantages of different paths to screen out the optimal memory allocation path.

[0082] Specifically, in one embodiment, the selected evaluation marker value can also be updated according to the selection evaluation value of the path between the starting node and the candidate node.

[0083] Among them, the optimal path determination method provided by the embodiments of the present application can be implemented based on heuristic algorithms such as the ant colony algorithm or particle swarm algorithm. The selected evaluation marker value includes pheromone and heuristic factor. The update of the selected evaluation marker value includes the update of pheromone. The update formula of pheromone: new pheromone = (current pheromone + current memory utilization rate) / 2. The selection evaluation value of the path between the starting node and the candidate node includes the current pheromone. The heuristic factor is updated according to the memory fragmentation rate. The setting of the heuristic factor is to sort the memory pool capacities from small to large. During the optimal path selection process, the heuristic factor preferentially selects memory pools with smaller remaining memory capacities (remaining memory resources), making the memory allocation scheme more compact, that is, the possibility of leaving large memory spaces is higher.

[0084] Based on the above embodiments, as an implementable manner, in one embodiment, according to the node information included in the optimal path, the best memory allocation strategy is determined, including:

[0085] Step 10331, according to the node information included in the optimal path, determine the target memory allocation results of each software module in the embedded device;

[0086] Step 10332: According to the target memory allocation results of each software module and the distribution of the remaining memory resources, locally adjust the target memory allocation results of each software module to obtain the optimal memory allocation results for each software module.

[0087] Step 10333: Determine the optimal memory allocation strategy according to the optimal memory allocation results of each software module.

[0088] Specifically, for the optimal path found in the memory allocation graph, for example , the node information it contains corresponds to the relevant data of the memory allocation of each software module. By parsing this node information, it is possible to clarify the memory resources initially allocated to each software module, that is, to determine the target memory allocation results of each software module in the embedded device. Further, it can be combined with the distribution of the remaining memory resources for further optimization. Because in actual memory allocation, the target memory allocation results may not be the most reasonable in terms of resource utilization. For example, after a software module is allocated to a memory pool, although the remaining memory in this memory pool meets the requirements, there are more suitable remaining resources in other nearby memory pools for this module, or there are memory fragments that can be further integrated and utilized. At this time, the target memory allocation results can be locally adjusted, such as reselecting a more suitable memory pool, to make full use of the remaining memory resources and obtain better optimal memory allocation results for each software module. Finally, after determining the optimal memory allocation results of each software module, these results are summarized and integrated to form the optimal memory allocation strategy for the entire embedded device.

[0089] Specifically, by locally adjusting in combination with the distribution of the remaining memory resources, further explore the utilization potential of the memory resources, reduce memory fragmentation, and improve the overall utilization rate of the memory, that is, make more full use of the limited memory resources and reduce the hardware cost.

[0090] Specifically, in one embodiment, for any software module, according to the target memory allocation result of this software module, determine multiple target memory pools of this software module and the memory resource allocation results in each target memory pool; for any target memory pool, obtain the remaining memory resource distribution of all candidate memory pools of the same type as this target memory pool; where the candidate memory pools include this target memory pool; according to the remaining memory resource distribution of all candidate memory pools, determine whether the target memory pool is the optimal memory pool; in the case where all target memory pools are the optimal memory pools, use this target memory allocation result as the optimal memory allocation result; in the case where any target memory pool is not the optimal memory pool, reselect the target memory pool from all candidate memory pools of the same type as this target memory pool.

[0091] Among them, the local adjustment of the target memory allocation result includes reselecting the target memory pool.

[0092] Specifically, for each software module, based on its target memory allocation result, multiple target memory pools for allocating memory to this module can be determined, as well as the specific quantity of memory resources allocated in each target memory pool. For example, the target memory allocation result of software module A shows that it obtains memory from memory pool and memory pool obtains memory, allocates 20MB in memory pool and allocates 15MB in memory pool . For each of the above-determined target memory pools, collect the remaining memory resource distribution information of all candidate memory pools of the same type (including the target memory pool itself). For example, if the target memory pool belongs to the cache type memory pool, then obtain the remaining memory capacity, memory fragmentation distribution, etc. of all memory pools belonging to the cache type (such as , etc.). Based on the remaining memory resource distribution of all candidate memory pools of the same type collected, determine whether the current target memory pool is the best choice. The judgment basis may cover the memory fragmentation rate, the continuity of the remaining memory, whether it can meet the possible future memory expansion requirements of the software module, etc. For example, although memory pool is currently one of the target memory pools of software module A, the remaining memory of the memory pool of the same type is less and can meet the memory demand of software A, and can better avoid the memory fragmentation problem, then memory pool is not the best memory pool. At this time, a suitable target memory pool can be reselected from all candidate memory pools of the same type, thereby adjusting the memory allocation scheme. For example, reallocate software module A from memory pool to memory pool .

[0093] Among them, by further judging and adjusting the target memory pool of the software module, the memory resources can be used more reasonably. For example, preferentially select memory pools that can reduce the memory fragmentation rate and improve memory continuity, which can fully tap the potential of the memory space, reduce memory waste caused by unreasonable allocation, and thus significantly improve the memory utilization rate.

[0094] Furthermore, in one embodiment, after obtaining the best memory allocation strategy, it is also possible to further allocate related modules to adjacent memory regions according to the call relationship and data sharing situation between software modules, that is, further fine-tune the best memory allocation strategy to reduce the latency of memory access.

[0095] Based on the above embodiments, Figure 3This is the overall flowchart of the memory allocation method provided by the embodiments of this application. As an implementable manner, in one embodiment, memory resources are allocated to each software module in the embedded device according to the optimal memory allocation strategy, including:

[0096] Step 1041, generate the firmware file of the embedded device according to the optimal memory allocation strategy;

[0097] Step 1042, compile the firmware file into the embedded device so that the embedded device can allocate memory resources for each software module by loading the firmware file.

[0098] Specifically, after generating the firmware file (C language header file) of the embedded device, file replacement is performed in the firmware code library of the embedded device, and the firmware file is generated into an executable firmware for the embedded device by starting firmware compilation. Finally, firmware burning is performed on the embedded device. After the embedded device is started for the first time, the actual memory resources are allocated to each software module based on the burned firmware, so that the software modules in the embedded device can run in the allocated memory space, realizing the entire memory allocation scheme from strategy determination to the actual application of the embedded device.

[0099] The memory allocation method provided by the embodiments of this application obtains the memory allocation limit conditions of the embedded device; generates multiple initial memory allocation strategies according to the memory allocation limit conditions; determines the optimal memory allocation strategy according to multiple initial memory allocation strategies according to the preset memory allocation screening conditions; and allocates memory resources to each software module in the embedded device according to the optimal memory allocation strategy. The method provided by the above solution generates multiple initial memory allocation strategies after obtaining the memory allocation limit conditions of the embedded device and determines the optimal strategy according to the preset screening conditions. It not only fully considers the memory requirements and limiting factors of each software module, but also realizes the automatic screening of the optimal strategy, improving the memory allocation efficiency while ensuring the rationality of the memory allocation strategy, laying a foundation for improving the overall performance and memory resource utilization rate of the embedded device. Moreover, through the determination of the optimal path and the local adjustment of the memory allocation result, the memory resources are extremely optimized, the manufacturing cost is reduced, and the development efficiency is improved.

[0100] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation manner.

[0101] The embodiments of this application also provide a memory allocation device for executing the memory allocation method provided by the above embodiments.

[0102] Such as Figure 4As shown in the figure, it is a schematic structural diagram of a memory allocation device provided by an embodiment of the present application. The memory allocation device 40 includes: an acquisition module 401, a generation module 402, a determination module 403, and an allocation module 404.

[0103] Among them, the acquisition module is used to acquire the memory allocation limit conditions of the embedded device; the generation module is used to generate multiple initial memory allocation strategies according to the memory allocation limit conditions; the determination module is used to determine the optimal memory allocation strategy according to multiple initial memory allocation strategies according to the preset memory allocation screening conditions; the allocation module is used to allocate memory resources to each software module in the embedded device according to the optimal memory allocation strategy.

[0104] For the description of the features in the embodiment corresponding to the memory allocation device, reference can be made to the relevant description of the embodiment corresponding to the memory allocation method, which will not be elaborated here one by one.

[0105] An embodiment of the present application further provides a memory allocation system for executing the memory allocation method provided by the above embodiment.

[0106] As Figure 5 shown in the figure, it is a schematic structural diagram of a memory allocation system provided by an embodiment of the present application. The memory allocation system includes: an embedded device and a memory allocation device, and the embedded device includes multiple software modules.

[0107] Among them, the memory allocation device is used to determine the optimal memory allocation strategy by using any of the above memory allocation methods and generate the firmware file of the embedded device; the embedded device is used to load the firmware file to perform corresponding memory resource allocation for each software module.

[0108] For the description of the features in the embodiment corresponding to the memory allocation system, reference can be made to the relevant description of the embodiment corresponding to the memory allocation method, which will not be elaborated here one by one.

[0109] An embodiment of the present application further provides an electronic device, as Figure 6 shown in the figure, it is a schematic structural diagram of an electronic device provided by an embodiment of the present application, including a processor 10 and a memory 20. The memory 20 stores a computer program, and the processor 10 is configured to run the computer program to execute the steps in any of the above memory allocation method embodiments.

[0110] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, wherein the computer program is configured to execute the steps in any of the above memory allocation method embodiments when running.

[0111] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: various media such as USB flash drives, read-only memory (ROM for short), random access memory (RAM for short), external hard drives, magnetic disks, or optical discs that can store computer programs.

[0112] The embodiments of the present application also provide a computer program product. The above computer program product includes a computer program, and when the computer program is executed by a processor, the steps in any of the above embodiments of the memory allocation method are implemented.

[0113] The embodiments of the present application also provide another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above embodiments of the memory allocation method are implemented.

[0114] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0115] The above has introduced in detail a memory allocation method, system, electronic device, and storage medium provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A memory allocation method, characterized in that: include: Get the memory allocation constraints of the embedded device; Generate multiple initial memory allocation strategies according to the memory allocation constraint conditions; According to the preset memory allocation screening conditions, and based on the multiple initial memory allocation strategies, determining the best memory allocation strategy; Allocating memory resources to each software module in the embedded device according to the optimal memory allocation strategy; The step of determining the best memory allocation strategy according to the preset memory allocation screening condition and the multiple initial memory allocation strategies includes: Generate a memory allocation graph according to the multiple initial memory allocation strategies; wherein the memory allocation graph includes a plurality of nodes, each node represents a memory allocation result of a single software module, and the memory allocation result includes memory allocation information of the software module in any memory pool; According to the preset memory allocation screening condition, searching for an optimal path on the memory allocation graph; An optimal memory allocation strategy is determined based on the node information included in the optimal path.

2. The memory allocation method according to claim 1, characterized in that: The generating a plurality of initial memory allocation strategies according to the memory allocation restriction condition includes: Determining a memory allocation target for each software module in the embedded device according to the memory allocation restriction condition; Generating a plurality of initial memory allocation strategies according to the memory allocation targets of the software modules; Wherein, any of the initial memory allocation strategies includes the memory allocation results of each of the software modules.

3. The memory allocation method according to claim 1, characterized in that: The memory allocation restriction condition includes at least the memory size, memory attributes, memory alignment requirements and the memory pool to which each software module belongs.

4. The memory allocation method according to claim 1, characterized in that: The searching for an optimal path on the memory allocation graph according to the preset memory allocation screening condition includes: Determining a path selection evaluation function according to the preset memory allocation screening condition; Based on the path selection evaluation function, an optimal path is found on the memory allocation graph.

5. The memory allocation method according to claim 4, characterized in that: The searching for an optimal path on the memory allocation graph based on the path selection evaluation function includes: Selecting at least one node on the memory allocation graph as a starting node; Based on the path selection evaluation function, calculating the selection evaluation value of the path between the starting node and the candidate nodes in the memory allocation graph other than the starting node; Determine the target path and the next node of the starting node according to the selection evaluation value of each path; wherein the next node is connected to the starting node through the target path; The next node is used as a new starting node, and the step of calculating the selection evaluation value of the path between the starting node and the candidate nodes in the memory allocation graph other than the starting node based on the path selection evaluation function is returned until the destination node is determined to obtain the optimal path of the memory allocation graph.

6. The memory allocation method according to claim 5, characterized in that: The calculating, based on the path selection evaluation function, the selection evaluation value of the path between the starting node and the candidate nodes other than the starting node in the memory allocation graph comprises: For any of the candidate nodes, based on the path selection evaluation function, according to the memory allocation result jointly represented by the starting node and the candidate node, determine the memory utilization rate and memory fragmentation rate of the embedded device; Obtaining a selection evaluation mark value of a path between the starting node and the node to be selected; Determining a selection evaluation value of a path between the start node and the node to be selected according to the selection evaluation mark value, the memory utilization rate and the memory fragmentation rate of the embedded device; The selection evaluation value is positively correlated with the memory utilization rate, and the selection evaluation value is negatively correlated with the memory fragmentation rate.

7. The memory allocation method according to claim 6, characterized in that: The method further comprises: The selection evaluation mark value is updated according to the selection evaluation value of the path between the starting node and the node to be selected.

8. The memory allocation method according to claim 1, characterized in that: Determining the best memory allocation strategy according to the node information included in the optimal path includes: Determining target memory allocation results of various software modules in the embedded device according to the node information included in the optimal path; According to the target memory allocation result of each software module and the distribution of the remaining memory resources, the target memory allocation result of each software module is locally adjusted to obtain the optimal memory allocation result of each software module; An optimal memory allocation strategy is determined based on the optimal memory allocation results of each software module.

9. The memory allocation method according to claim 8, characterized in that: The target memory allocation results of each software module and the distribution of remaining memory resources, and locally adjusting the target memory allocation results of each software module, including: For any of the software modules, determining multiple target memory pools of the software module and memory resource allocation results in each of the target memory pools according to the target memory allocation result of the software module; For any of the target memory pools, obtain the remaining memory resource distribution of all candidate memory pools of the same type as the target memory pool; wherein the candidate memory pools include the target memory pool; Determine whether the target memory pool is the best memory pool according to the remaining memory resource distribution of all candidate memory pools; In the case that each of the target memory pools is an optimal memory pool, the target memory allocation result is used as the optimal memory allocation result; In the case that any of the target memory pools is not the best memory pool, reselecting a target memory pool from all candidate memory pools of the same type as the target memory pool; The local adjustment of the target memory allocation result includes reselecting a target memory pool.

10. The memory allocation method according to claim 1, characterized in that: The allocating memory resources to each software module in the embedded device according to the optimal memory allocation strategy includes: Generating a firmware file for the embedded device according to the optimal memory allocation strategy; The firmware file is compiled into the embedded device, so that the embedded device allocates memory resources for each software module by loading the firmware file.

11. A memory allocation system, characterized in that: include: An embedded device and a memory allocation device, wherein the embedded device includes a plurality of software modules; The memory allocation device is used to adopt the memory allocation method according to any one of claims 1 to 10 to determine the best memory allocation strategy and generate a firmware file for the embedded device; The embedded device is used to load the firmware file to allocate corresponding memory resources to each of the software modules.

12. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the memory allocation method as claimed in any one of claims 1 to 10 when executing the computer program.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the memory allocation method according to any one of claims 1 to 10.

14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the memory allocation method according to any one of claims 1 to 10 are implemented.

Citation Information

Patent Citations

  • Memory allocation method and device, equipment and storage medium

    CN114168309A