Memory allocation method and system, electronic equipment and storage medium

By obtaining the memory allocation restrictions of embedded devices, generating and filtering memory allocation policies, the problems of low memory allocation efficiency and inability to guarantee policy rationality are solved, and efficient memory resource utilization and device performance improvement are achieved.

CN119883653AActive Publication Date: 2025-04-25SHANDONG YUNHAI GUOCHUANG CLOUD COMPUTING EQUIP IND INNOVATION CENT CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202510362118.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-26
Publication Date
2025-04-25
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 limit conditions of the embedded device, multiple initial memory allocation policies are generated, and the optimal memory allocation policy is determined according to the preset filter conditions, and finally allocating memory resources to each software module in the embedded device.

Benefits of technology

While improving memory allocation efficiency, it ensures the rationality of memory allocation strategies, thereby improving the overall performance and memory resource utilization of embedded devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883653A_ABST
    Figure CN119883653A_ABST
Patent Text Reader

Abstract

The invention discloses a memory allocation method and system, electronic equipment and a storage medium, and relates to the technical field of computers, and the method comprises the following steps: generating a plurality of initial memory allocation strategies after acquiring memory allocation limiting conditions of embedded equipment, and determining an optimal strategy according to a preset screening condition, according to the method, the memory requirements and limiting factors of all software modules are fully considered, automatic screening of the optimal strategy is achieved, the reasonability of the memory allocation strategy is guaranteed while the memory allocation efficiency is improved, and a foundation is laid for improving the overall performance of embedded equipment and the utilization rate of memory resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present 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] At present, embedded devices are widely used in many fields. Affected by the application scenarios of embedded devices, their memory is limited by many factors. Therefore, how to reasonably allocate memory for embedded devices has become a key issue in the development of embedded devices.

[0003] In the related art, the memory allocation strategy of embedded devices is usually formulated by manual and exhaustive methods. However, with the increase of embedded device function modules and the expansion of data scale, the manual and exhaustive methods reduce the efficiency of memory allocation, and the rationality of memory allocation strategy cannot be guaranteed. Summary of the invention

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

[0005] The present application provides a memory allocation method, including: Get the memory allocation constraints of the embedded device; Generate multiple initial memory allocation strategies according to memory allocation constraints; According to the preset memory allocation screening conditions and multiple initial memory allocation strategies, determine the best memory allocation strategy; Allocate memory resources to each software module in the embedded device according to the optimal memory allocation strategy.

[0006] The present application also provides a memory allocation device, comprising: The acquisition module is used to obtain the memory allocation constraints of the embedded device; A generation module, used to generate multiple initial memory allocation strategies according to memory allocation constraints; A determination module, used to determine the best memory allocation strategy according to preset memory allocation screening conditions and multiple initial memory allocation strategies; The allocation module is used to allocate memory resources to various software modules in the embedded device according to the optimal memory allocation strategy.

[0007] The present application also provides a memory allocation system, comprising: an embedded device and a memory allocation device, wherein the embedded device comprises a plurality of software modules; The memory allocation device is used to determine the best memory allocation strategy and generate a firmware file for the embedded device by using any of the above memory allocation methods; The embedded device is used to load the firmware file to allocate the corresponding memory resources to each software module.

[0008] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any one of the above-mentioned memory allocation methods when executing the computer program.

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

[0010] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned memory allocation methods when executed by a processor.

[0011] Through this application, after obtaining the memory allocation constraints of the embedded device, a variety of 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 constraints of each software module, but also realizes the automatic screening of the optimal strategy. While improving the memory allocation efficiency, the rationality of the memory allocation strategy is guaranteed, laying the foundation for improving the overall performance of embedded devices and memory resource utilization. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0013] Figure 1 A flowchart of a memory allocation method provided in an embodiment of the present application; Figure 2 A schematic diagram of the structure of a memory allocation diagram provided in an embodiment of the present application; Figure 3 A schematic diagram of the overall process of the memory allocation method provided in an embodiment of the present application; Figure 4 A schematic diagram of the structure of a memory allocation device provided in an embodiment of the present application; Figure 5 A schematic diagram of the structure of the memory allocation system provided in an embodiment of the present application; Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0014] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

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

[0016] Embedded devices are widely used computer devices, and their memory allocation is limited due to the following reasons: Cost constraints: Embedded devices often need to control costs to adapt to the needs of mass production and consumer markets.

[0017] Power Constraints: The size and type of memory affects the power consumption of the device. In battery-powered or low-power devices, smaller memory helps reduce energy consumption.

[0018] Space constraints: Many embedded devices are small and space-constrained, thus requiring compact hardware design, including memory.

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

[0020] Real-time performance: Some embedded systems require fast response. Using smaller memory can reduce access delays and improve the real-time performance of the system.

[0021] Specialization: Embedded systems are often optimized for specific applications and therefore require only enough memory to meet those specific needs.

[0022] Due to these limitations, embedded system designers need to carefully manage memory resources. In embedded devices, there are many static memory usage scenarios. The size and location of these static memories are generally specified during the firmware code writing process, and they will not change during use. If this part of static memory is allocated reasonably, it is very important for embedded devices. Reasonable static memory allocation can greatly reduce costs. However, static memory allocation is essentially a packing problem, which has been proven to be an NP-complete problem, which means that there is no known polynomial time algorithm that can accurately solve all instances. There are several general ways to allocate static memory: Developers manually allocate memory. In this way, each memory layout change needs to be manually allocated, which is time-consuming, labor-intensive, and prone to errors. If memory allocation overlaps, it may cause problems such as memory overflow, which are difficult to locate.

[0023] Using dynamic programming to exhaustively solve all problems takes a lot of time, and the time consumption increases dramatically as the data size increases. For those who have time requirements, dynamic programming is not suitable.

[0024] Among them, NP-Complete problems are an important concept in computational complexity theory. NP stands for "Non-deterministic Polynomial time", and "Complete" means that this type of problem is representative of 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 the problem is NP-Complete.

[0025] In order to solve the above technical problems, the embodiments of the present application provide a memory allocation method, system, electronic device and storage medium, the method comprising: obtaining memory allocation constraints of embedded devices; generating multiple initial memory allocation strategies according to memory allocation constraints; determining the best memory allocation strategy according to preset memory allocation screening conditions and multiple initial memory allocation strategies; allocating memory resources to each software module in the embedded device according to the best memory allocation strategy. The method provided by the above scheme generates multiple initial memory allocation strategies after obtaining the memory allocation constraints of embedded devices, and determines the best strategy according to preset screening conditions. It not only fully considers the memory requirements and constraints of each software module, but also realizes the automatic screening of the best strategy. While improving the memory allocation efficiency, it ensures the rationality of the memory allocation strategy, laying a foundation for improving the overall performance and memory resource utilization of embedded devices.

[0026] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0027] The embodiment of the present application provides a memory allocation method for formulating a memory allocation strategy for an embedded device during the development of the embedded device. The execution subject of the embodiment of the present 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.

[0028] like Figure 1 FIG. 1 is a flow chart of a memory allocation method provided in an embodiment of the present application, and the method includes: Step 101, obtaining memory allocation restriction conditions of an embedded device.

[0029] Among them, the memory allocation restriction condition is 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. The memory allocation constraint information includes the memory attribute, memory alignment requirement and the memory pool to which each software module belongs. That is, the memory allocation restriction condition at least includes the memory size, memory attribute, memory alignment requirement and the memory pool to which each software module belongs. Among them, the software module includes functional modules such as user registration module and display module.

[0030] 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 (the size of the static memory occupied), and the module memory allocation constraint information (memory attributes, alignment requirements, and specified memory pool). An exemplary static memory configuration table is shown in Table 1 below: Table 1

[0031] Specifically, the memory allocation restriction condition of the embedded device can be determined by analyzing the static memory configuration table filled in by the user offline.

[0032] Step 102: Generate multiple initial memory allocation strategies according to memory allocation constraints.

[0033] 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, the embodiment of the present application first generates a variety of initial memory allocation strategies that can be met under limited static memory resources based on the memory allocation restriction conditions. Taking the 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.

[0034] Specifically, in one embodiment, the memory allocation target of each software module in the embedded device can be determined according to the memory allocation restriction condition; and a plurality of initial memory allocation strategies can be generated according to the memory allocation target of each software module.

[0035] The memory allocation target of a single software module is a row of entry information in Table 1 above, that is, the memory allocation target includes memory size, memory attributes, memory alignment requirements and the memory pool to which it belongs.

[0036] Specifically, after clarifying the memory allocation constraints, you can plan memory allocation plans for each software module based on these conditions, and generate multiple initial memory allocation strategies by trying different memory allocation combinations. Each strategy contains the memory allocation results of each software module, that is, it determines how much memory each module gets from which memory pool. For example, one strategy can give priority to modules with high speed requirements and allocate high-speed memory pools to modules with high speed requirements, while another strategy can first meet modules with large memory requirements. Through diversified allocation combinations, more options are provided for subsequent screening of the best strategy.

[0037] Step 103: Determine the best memory allocation strategy according to the preset memory allocation screening conditions and multiple initial memory allocation strategies.

[0038] It should be noted that the preset memory allocation filter conditions are the criteria for evaluating and selecting the optimal memory allocation solution.

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

[0040] Step 104: Allocate memory resources to each software module in the embedded device according to the optimal memory allocation strategy.

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

[0042] Based on the above embodiment, as an implementable manner, in one embodiment, according to the preset memory allocation screening conditions, according to multiple initial memory allocation strategies, the best memory allocation strategy is determined, including: Step 1031, generating a memory allocation graph according to a plurality of 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; Step 1032, searching for an optimal path on a memory allocation graph according to a preset memory allocation screening condition; Step 1033, determining the best memory allocation strategy according to the node information included in the optimal path.

[0043] For example, Figure 2 As shown, it is a structural schematic diagram of the memory allocation map provided in an embodiment of the present application. The memory allocation map presents different initial memory allocation strategies in a graphical manner. Figure 2 The memory allocation diagram shown is actually a state transition diagram of memory allocation, which shows the different possibilities and path relationships of software module memory allocation. Indicates four memory pools. These four memory pools include memory pools of various memory attribute types, such as an SRAM memory pool and a DDR memory pool. , and Indicates three memory states, i.e., the superscript indicates the current memory pool state after the next level of state migration, for example, Represents a memory pool The memory status (remaining memory resources) when allocating memory to module A. Represents a memory pool After allocating memory resources to module A, the memory status when allocating memory to module B, and so on. The figure divides module A, module B, and module C, indicating that this is the memory allocation for different software modules. Each module has multiple selectable memory allocation nodes, which means that each module has multiple possible memory allocation methods. The lines between nodes represent the memory allocation path. Different combinations of lines constitute different memory allocation strategy paths, which can be used to subsequently screen the best memory allocation solution.

[0044] Among them, when selecting the optimal path, it is subject to the following constraints: Constraint 1: If the path is , and after module m, then , and requires , otherwise the path is invalid, which ensures that there is enough memory resource left after allocation and avoids negative memory amount.

[0045] Constraint 2: If the path is , the corresponding state needs to be guaranteed during the state migration process The allocated memory attributes meet the requirements, that is, the allocated memory resources are guaranteed to have the characteristics required for the operation of the software module, such as read and write speed, cache characteristics, etc.

[0046] Constraint 3: If the path is During the state migration 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.

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

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

[0049] Specifically, in one embodiment, a path selection evaluation function may be determined according to a preset memory allocation screening condition; and based on the path selection evaluation function, an optimal path may be found on a memory allocation graph.

[0050] 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 memory utilization, reducing memory fragmentation, and meeting the requirements of each software module for memory attributes and alignment. The path selection evaluation function quantifies these conditions into computable mathematical expressions to facilitate subsequent evaluation and selection of the optimal path.

[0051] Specifically, the memory allocation graph shows various possible combinations 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 best value (such as maximum or minimum) is the optimal path. The memory allocation method corresponding to the optimal path is the solution that best meets the memory allocation requirements of embedded devices under the current preset conditions, and can achieve efficient utilization and reasonable allocation of memory resources.

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

[0053] Specifically, after selecting the starting node, the selection evaluation value of the path between the starting node and other candidate nodes is calculated based on the path selection evaluation function. The path selection evaluation function integrates the pheromone concentration and the heuristic factor, that is, the evaluation function comprehensively considers various factors of memory allocation, such as memory utilization and memory fragmentation rate. The target path and the next node of the starting node are determined according to the selection evaluation value of each path, that is, the memory allocation is guided to develop in a more optimal direction. The next node is used as the new starting node, and the above calculation and selection process is repeated until the destination node is determined.

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

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

[0056] Specifically, the start node represents the current memory allocation state of a software module, e.g. Figure 2 In , the candidate node represents the memory allocation status that other software modules can obtain. The combination of these two nodes presents the memory allocation change. By analyzing the memory usage after this change, the memory utilization and memory fragmentation rate of the embedded device can be determined. The memory utilization rate is the proportion of used memory to total memory, reflecting the degree of memory utilization, and the memory fragmentation rate is the proportion of small memory blocks that cannot be effectively used in the memory, reflecting the degree of memory fragmentation. These two indicators are important bases for measuring the quality of memory allocation solutions.

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

[0058] Specifically, in one embodiment, the selection evaluation mark value may also be updated according to the selection evaluation value of the path between the start node and the node to be selected.

[0059] Among them, the optimal path determination method provided in the embodiment of the present application can be implemented based on heuristic algorithms such as ant colony algorithm or particle swarm algorithm, the selection evaluation mark value includes pheromone and heuristic factor, the update of the selection evaluation mark value includes the update of pheromone, the update formula of pheromone is: new pheromone = (current pheromone + current memory utilization) / 2, and 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 capacity of the memory pool from small to large. The heuristic factor gives priority to the memory pool with smaller remaining memory capacity (remaining memory resources) in the process of executing the optimal path selection, so that the memory allocation plan is more compact, that is, the possibility of leaving a large block of memory space is higher.

[0060] Based on the above embodiment, as an implementable manner, in one embodiment, determining the best memory allocation strategy according to the node information included in the optimal path includes: Step 10331, determining the target memory allocation result of each software module in the embedded device according to the node information included in the optimal path; Step 10332, based on the target memory allocation result of each software module and the distribution of the remaining memory resources, locally adjust the target memory allocation result of each software module to obtain the optimal memory allocation result of each software module; Step 10333, determine the best memory allocation strategy based on the best memory allocation results of each software module.

[0061] Specifically, for the optimal path found in the memory allocation graph, e.g. , the node information it contains corresponds to the relevant data of memory allocation of each software module. By parsing these 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, and further optimize it in combination with the distribution of remaining memory resources. Because in actual memory allocation, the target memory allocation result may not be the most reasonable resource utilization. For example, after a software module is allocated to a memory pool, although the remaining memory of the memory pool meets the requirements, other nearby memory pools have more suitable remaining resources for the module, or there are memory fragments that can be further integrated and utilized. At this time, the target memory allocation result can be partially adjusted, such as reselecting a more suitable memory pool to make full use of the remaining memory resources and obtain a better optimal memory allocation result for each software module. Finally, after determining the optimal memory allocation result for each software module, these results are summarized and integrated to form the optimal memory allocation strategy for the entire embedded device.

[0062] Specifically, by making local adjustments based on the distribution of remaining memory resources, we can further tap the utilization potential of memory resources, reduce memory fragmentation, and improve the overall memory utilization, that is, make more effective use of limited memory resources and reduce hardware costs.

[0063] Specifically, in one embodiment, for any software module, multiple target memory pools of the software module and memory resource allocation results in each target memory pool can be determined according to the target memory allocation result of the software module; for any target memory pool, the remaining memory resource distribution of all candidate memory pools of the same type as the target memory pool is obtained; wherein the candidate memory pools include the target memory pool; according to the remaining memory resource distribution of all candidate memory pools, it is determined whether the target memory pool is the best memory pool; if all target memory pools are the best memory pools, the target memory allocation result is used as the best memory allocation result; if any target memory pool is not the best memory pool, the target memory pool is reselected from all candidate memory pools of the same type as the target memory pool.

[0064] The local adjustment of the target memory allocation result includes reselecting the target memory pool.

[0065] Specifically, for each software module, based on its target memory allocation result, multiple target memory pools for allocating memory to the module and the specific amount of memory resources allocated in each target memory pool can be determined. For example, the target memory allocation result of software module A shows that it allocates memory from memory pool and memory pool Get memory in the memory pool Allocate 20MB in the memory pool 15MB is allocated in the target memory pool. For each target memory pool determined above, the remaining memory resource distribution information of all candidate memory pools of the same type (including the target memory pool itself) is collected. For example, if the target memory pool If it is a cache type memory pool, then get all memory pools of the same cache type (such as Based on the remaining memory resource distribution of all candidate memory pools of the same type, determine whether the current target memory pool is the best choice. The judgment may include memory fragmentation rate, continuity of remaining memory, whether it can meet the possible future memory expansion requirements of software modules, etc. For example, although the memory pool Currently it is one of the target memory pools of software module A, but the same type of memory pool The remaining memory is smaller and can meet the memory requirements of software A, which can better avoid memory fragmentation problems. It is not the best memory pool. In this case, you can reselect a suitable target memory pool from all candidate memory pools of the same type to adjust the memory allocation plan. For example, remove software module A from the memory pool. Reallocate to memory pool .

[0066] Among them, by further judging and adjusting the target memory pool of the software module, memory resources can be used more reasonably. For example, giving priority to memory pools that can reduce memory fragmentation rate and improve memory continuity can fully tap the potential of memory space and reduce memory waste caused by unreasonable allocation, thereby significantly improving memory utilization.

[0067] Furthermore, in one embodiment, after obtaining the optimal memory allocation strategy, related modules can be further allocated to adjacent memory areas based on the calling relationship and data sharing between software modules, that is, the optimal memory allocation strategy can be further fine-tuned to reduce memory access delays.

[0068] Based on the above embodiments, Figure 3 The overall flow diagram of the memory allocation method provided in the embodiment of the present application is as an implementable method. In one embodiment, memory resources are allocated to each software module in the embedded device according to the optimal memory allocation strategy, including: Step 1041, generating a firmware file for the embedded device according to the optimal memory allocation strategy; Step 1042, compile the firmware file into the embedded device, so that the embedded device allocates memory resources for each software module by loading the firmware file.

[0069] Specifically, after generating the firmware file (C language header file) of the embedded device, the file is replaced in the firmware code base of the embedded device, and the firmware file is generated into an executable firmware for the embedded device by starting the firmware compilation, and finally the firmware is burned to the embedded device. After the embedded device is started for the first time, the actual allocation of memory resources to each software module is performed 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 solution from policy determination to the actual application of the embedded device.

[0070] The memory allocation method provided in the embodiment of the present application obtains the memory allocation restriction conditions of the embedded device; generates multiple initial memory allocation strategies according to the memory allocation restriction conditions; determines the best memory allocation strategy according to the preset memory allocation screening conditions and the multiple initial memory allocation strategies; allocates memory resources to each software module in the embedded device according to the best memory allocation strategy. The method provided by the above scheme generates multiple initial memory allocation strategies after obtaining the memory allocation restriction conditions of the embedded device, and determines the best strategy according to the preset screening conditions. It not only fully considers the memory requirements and restriction factors of each software module, but also realizes the automatic screening of the best strategy. While improving the memory allocation efficiency, it ensures the rationality of the memory allocation strategy, laying the foundation for improving the overall performance and memory resource utilization of the embedded device. In addition, by determining the optimal path and adjusting the memory allocation results locally, the extreme optimization of memory resources is achieved, the manufacturing cost is reduced, and the development efficiency is improved.

[0071] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.

[0072] An embodiment of the present application also provides a memory allocation device for executing the memory allocation method provided in the above embodiment.

[0073] like Figure 4 , which is a schematic diagram of the structure of a memory allocation device provided in an embodiment of the present application. The memory allocation device 40 comprises: an acquisition module 401, a generation module 402, a determination module 403 and an allocation module 404.

[0074] Among them, the acquisition module is used to obtain the memory allocation restriction conditions of the embedded device; the generation module is used to generate multiple initial memory allocation strategies according to the memory allocation restriction conditions; the determination module is used to determine the best memory allocation strategy according to the preset memory allocation screening conditions and multiple initial memory allocation strategies; the allocation module is used to allocate memory resources to each software module in the embedded device according to the best memory allocation strategy.

[0075] The description of the features in the embodiment corresponding to the memory allocation device can refer to the relevant description of the embodiment corresponding to the memory allocation method, which will not be repeated here.

[0076] An embodiment of the present application also provides a memory allocation system for executing the memory allocation method provided in the above embodiment.

[0077] like Figure 5 , which is a schematic diagram of the structure of a memory allocation system provided in an embodiment of the present application. The memory allocation system includes: an embedded device and a memory allocation device, wherein the embedded device includes multiple software modules.

[0078] The memory allocation device is used to adopt any of the above-mentioned memory allocation methods 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 software module.

[0079] The description of the features in the embodiment corresponding to the memory allocation system can refer to the relevant description of the embodiment corresponding to the memory allocation method, which will not be repeated here.

[0080] The embodiment of the present application also provides an electronic device, such as Figure 6 As shown, it is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, including a processor 10 and a memory 20, in which a computer program is stored, and the processor 10 is configured to run the computer program to execute the steps in any one of the above-mentioned memory allocation method embodiments.

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

[0082] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0083] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above-mentioned memory allocation method embodiments are implemented.

[0084] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, wherein 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-mentioned memory allocation method embodiments are implemented.

[0085] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0086] The above is a detailed introduction to a memory allocation method, system, electronic device and storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of ​​the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection 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; According to the optimal memory allocation strategy, memory resources are allocated to each software module in the embedded device.

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 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.

5. The memory allocation method according to claim 4, 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.

6. The memory allocation method according to claim 5, 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.

7. The memory allocation method according to claim 6, 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.

8. The memory allocation method according to claim 7, 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.

9. The memory allocation method according to claim 4, 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.

10. The memory allocation method according to claim 9, 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.

11. 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.

12. 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 11 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.

13. 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 11 when executing the computer program.

14. 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 11.

15. 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 11 are implemented.

Citation Information

Patent Citations

  • Memory allocation method and device, equipment and storage medium

    CN114168309A

  • Distributed task scheduling method and device, storage medium and electronic equipment

    CN116719631A

  • Task scheduling method and device of multi-engine computing system and storage medium

    CN116820730A

  • Intelligent data aggregation software system based on Internet of Things

    CN117971173A

  • Chip platform hardware abstraction layer construction method

    CN119312219A