Memory allocation method and device, terminal equipment and computer readable storage medium
By combining dynamic and fixed partitioning algorithms, the memory allocation method is dynamically adjusted according to the program running time of the embedded device, solving the problem of memory waste and fragmentation, improving the memory allocation speed and efficiency, and meeting the memory management needs of the embedded device.
Patent Information
- Application Number
- CN202410674578.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2024-09-10
AI Technical Summary
The memory management of existing embedded devices has the problems of memory waste, memory fragmentation and slow allocation speed, making it difficult to meet their efficient memory allocation requirements.
Adopt a hybrid memory allocation strategy that combines dynamic partitioning algorithm and fixed partitioning algorithm to dynamically adjust the memory allocation method according to the running time of the program, record and optimize partition information to reduce memory fragmentation and improve memory allocation speed.
By dynamically adjusting the memory allocation method, memory fragmentation is reduced, memory allocation speed and efficiency are improved, and the memory management needs of embedded devices are met.
Smart Images

Figure CN118626255A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a memory allocation method, apparatus, terminal device and computer-readable storage medium. Background Art
[0002] With the wide application and increasing functional requirements of embedded devices, the demand for optimizing their memory management is becoming increasingly urgent. Embedded devices usually have limited memory resources, and their memory allocation and release operations have a significant impact on device performance and power consumption. Current memory allocation algorithms such as fixed partitions, dynamic partitions, and buddy systems have some problems, such as memory waste, memory fragmentation, and slow allocation speed. Summary of the invention
[0003] The present application provides a memory allocation method, which can dynamically implement memory allocation and improve memory allocation efficiency.
[0004] In a first aspect, the present application provides a memory allocation method, the method comprising:
[0005] Get the current running time of the target program;
[0006] If the current running time is less than or equal to the target time threshold, memory is allocated to the target program according to a default memory allocation method;
[0007] If the current running time is greater than the target time threshold, a target memory allocation mode matching the current running time is determined, and memory is allocated to the target program using the target memory allocation mode.
[0008] In some embodiments of the present application, determining a target memory allocation mode that matches the current running time includes:
[0009] Determine whether there is a memory allocation information table in the target storage location; the memory allocation information table stores the correspondence between different operating time and different memory allocation modes;
[0010] If the memory allocation information table exists in the target storage location, a target memory allocation mode matching the current running time is determined based on the memory allocation information table.
[0011] In some embodiments of the present application, after determining the target memory allocation mode matching the current running time according to the corresponding relationship, the method further includes:
[0012] Determine current memory allocation information corresponding to the target program under the running time;
[0013] Determine the target running time that the running time matches in the memory allocation information table;
[0014] Determine target memory allocation information corresponding to the target runtime;
[0015] Determine whether the current memory allocation information matches the target memory allocation information;
[0016] If the current memory allocation information does not match the target memory allocation information, the target memory allocation information is replaced with the current memory allocation information to update the memory allocation mode in the memory allocation information table.
[0017] In some embodiments of the present application, the memory allocation information includes memory allocation areas of different unit types and the number of memory allocation areas under each unit type;
[0018] The determining whether the current memory allocation information matches the target memory allocation information includes:
[0019] Determine whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same;
[0020] If the number of types is the same, taking the number of memory allocation areas corresponding to the current memory allocation information in each of the same memory allocation types as the first number of memory allocation areas and the number of memory allocation areas corresponding to the target memory allocation information as the second number of memory allocation areas, determine whether the numbers of each of the second memory allocation areas are greater than or equal to the corresponding number of the first memory allocation areas;
[0021] If the number of each of the second memory allocation areas is greater than or equal to the number of the corresponding first memory allocation areas, determining that the current memory allocation information matches the target memory allocation information;
[0022] If at least one of the second memory allocation area numbers is smaller than the corresponding first memory allocation area number, it is determined that the current memory allocation information does not match the target memory allocation information.
[0023] In some embodiments of the present application, replacing the target memory allocation information with the current memory allocation information includes:
[0024] The second memory allocation area quantity is replaced by the first memory allocation area quantity to update the memory allocation mode in the memory allocation information table.
[0025] In some embodiments of the present application, after determining whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same, the method further includes:
[0026] If the number of types is not the same, determining the memory allocation area of the target unit type that exists in the current memory allocation information and does not exist in the target memory allocation information and the number corresponding to the memory allocation area of the target unit type;
[0027] The memory allocation area of the target unit type and the number corresponding to the memory allocation area of the target unit type are added to the target memory allocation information to update the memory allocation method in the memory allocation information table.
[0028] In some embodiments of the present application, after determining whether there is a memory allocation information table in the target storage location, the method includes:
[0029] If the memory allocation information table does not exist in the target storage location, the preset dynamic memory allocation mode is determined as the target memory allocation mode that matches the current running time.
[0030] In a second aspect, the present application further provides a memory allocation device, the device comprising:
[0031] The acquisition module is used to obtain the current running time of the target program;
[0032] An allocation module, configured to allocate memory to the target program according to a default memory allocation method if the current running time is less than or equal to a target time threshold;
[0033] The allocation module is also used to determine a target memory allocation method that matches the current running time if the current running time is greater than the target time threshold, and allocate memory to the target program using the target memory allocation method.
[0034] In a third aspect, the present application also provides a terminal device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps in any one of the memory allocation methods described.
[0035] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the steps in any one of the memory allocation methods described.
[0036] The memory allocation method provided in the present application can first obtain the running time of the program, and use different memory allocation schemes for the program according to the running time of the program, thereby realizing dynamic allocation of memory and improving memory allocation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0038] Figure 1 is a scenario diagram of a memory allocation system provided in an embodiment of the present application;
[0039] Figure 2 This is a flowchart of an embodiment of the memory allocation method in the embodiment of the present application;
[0040] Figure 3 It is a functional module schematic diagram of the memory allocation device in an embodiment of the present application;
[0041] Figure 4 It is a schematic diagram of the structure of the terminal device in the embodiment of the present application. DETAILED DESCRIPTION
[0042] 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 those skilled in the art without creative work are within the scope of protection of this application.
[0043] In the description of the present application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the feature. In the description of the present application, "plurality" means two or more, unless otherwise clearly and specifically defined.
[0044] In this application, the word "exemplary" is used to mean "used as an example, illustration or description". Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. At the same time, it is to be understood that in the specific implementation of this application, when user information, user data and other related data are involved, when the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data shall comply with relevant laws, regulations and standards of relevant countries and regions.
[0045] In order to enable any person skilled in the art to implement and use the present application, the following description is provided. In the following description, details are listed for the purpose of explanation. It should be understood that those of ordinary skill in the art will recognize that the present application can be implemented without using these specific details. In other examples, known structures and processes will not be elaborated in detail to avoid unnecessary details that make the description of the present application obscure. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest range of principles and features disclosed in the present application.
[0046] The present application provides a memory allocation method, apparatus, device and storage medium, which are described in detail below.
[0047] According to the above background technology, an efficient memory allocation method is needed. Based on this, the core idea of the present invention is to combine the dynamic partitioning algorithm and the fixed partitioning algorithm to optimize the memory management of the embedded device.
[0048] In terms of specific implementation, a hybrid memory allocation strategy can be adopted. First, the program is run using a dynamic partitioning algorithm to dynamically allocate memory space to meet the real-time needs of the program. During the program running process, the partition information of the program under peak memory and normal memory is recorded, including the partition size and number. Then, optimization is performed based on these partition information.
[0049] In the initialization phase of the program, the idea of a fixed partition algorithm is introduced. According to the recorded partition information, a linked list of partitions and sizes is fixedly allocated as the allocated memory space. In this way, the program can directly obtain the required size of memory from the allocated space during operation, reducing memory fragmentation and allocation time.
[0050] By combining the dynamic partitioning algorithm with the fixed partitioning algorithm, this application can reduce memory fragmentation problems and improve memory allocation speed and efficiency while providing real-time memory requirements. This hybrid memory allocation strategy is flexible and efficient, and can better meet the memory management needs of embedded devices.
[0051] See also Figure 1 , Figure 1 The following is a schematic diagram of a memory allocation system provided in an embodiment of the present application. The memory allocation system may include a terminal device 100, and different memory allocation methods are configured in the terminal device 100. When the terminal device 100 runs a program, corresponding memory allocation may be performed for the program, for example, the memory allocation method in the present application is executed.
[0052] In the embodiment of the present application, the terminal device 100 includes but is not limited to a desktop computer, a portable computer, a network server, a PDA (Personal Digital Assistant), a tablet computer, a wireless terminal device, an embedded device, etc.
[0053] It should be noted that Figure 1 The scenario diagram of the memory allocation system shown is only an example. The memory allocation system and scenario described in the embodiment of the present application are intended to more clearly illustrate the technical solution of the embodiment of the present application, and do not constitute a limitation on the technical solution provided in the embodiment of the present application. Ordinary technicians in this field can know that with the evolution of the memory allocation system and the emergence of new business scenarios, the technical solution provided in the embodiment of the present application is also applicable to similar technical problems.
[0054] like Figure 2 As shown, Figure 2 This is a flow chart of an embodiment of a memory allocation method in an embodiment of the present application. The memory allocation method may include the following steps 201 to 203:
[0055] 201. Get the current running time of the target program.
[0056] In the embodiment of the present application, the target program can be any program running in the terminal device, and the specific embodiment of the present application is not limited. When the target program is running, the processing module of the terminal device, such as the CPU, times the target program to obtain the current running time of the target program.
[0057] 202. If the current running time is less than or equal to the target time threshold, memory is allocated to the target program according to a default memory allocation method.
[0058] First of all, it should be noted that the longer the program runs, the more data the program calculates, and the more memory usage increases. Therefore, after obtaining the current running time of the target program, the memory allocation method used by the current target program can be determined based on the preset target time threshold.
[0059] In the embodiment of the present application, when the current running time of the target program is less than or equal to the target time threshold, it can be characterized that the current data calculation amount of the target program is small, and at this time, the default memory allocation method can be used. Among them, the default memory allocation method can include any preset memory allocation method, and the embodiment of the present application does not limit the default memory allocation method.
[0060] 203. If the current running time is greater than the target time threshold, determine a target memory allocation method that matches the current running time, and allocate memory to the target program using the target memory allocation method.
[0061] In the embodiment of the present application, when the current running time of the target program is greater than the target time threshold, it can be characterized that the current data calculation amount of the target program is large, and at this time, a memory allocation method matching the current running time is determined for allocation. Among them, the memory occupancy used by the memory allocation method matching the current running time can be the memory occupancy of the default memory allocation method.
[0062] The memory allocation method provided in the present application can first obtain the running time of the program, and use different memory allocation schemes for the program according to the running time of the program, thereby realizing dynamic allocation of memory and improving memory allocation efficiency.
[0063] In order to better implement the embodiment of the present application, in one embodiment of the present application, determining a target memory allocation method that matches the current running time includes:
[0064] Determine whether there is a memory allocation information table in the target storage location; the memory allocation information table stores the correspondence between different running time and different memory allocation methods; if there is a memory allocation information table in the target storage location, determine the target memory allocation method that matches the current running time based on the memory allocation information table.
[0065] The above embodiment provides a memory allocation solution, and the embodiment of the present application also provides a memory allocation solution.
[0066] Specifically, in an embodiment of the present application, the target storage location may be a fixed storage location in a storage device of the terminal device. The fixed storage location may be used to specifically store the memory allocation information table. When it is necessary to allocate memory to the target program, there is no need to traverse the storage device, and only the memory allocation information table needs to be obtained from the fixed storage location.
[0067] In addition, a variety of memory allocation methods can be stored in the memory allocation information table. If the current running time is greater than the target time threshold, the current running time can also be compared with each time interval to determine which specific target time interval the current running time belongs to. At the same time, each time interval can correspond to a memory allocation method, and the larger the time interval, the larger the memory occupancy of the corresponding memory allocation method. Furthermore, it can be achieved that if the current running time is longer, the target program obtains a larger allocated memory to meet the memory usage of the target program. In this way, determining the memory allocation method corresponding to different running times by means of the memory allocation information table can improve memory efficiency, without the need for the CPU technology to calculate all the data of the current program, and then allocate according to the data amount, reducing the CPU calculation memory allocation process.
[0068] In order to better implement the embodiment of the present application, in one embodiment of the present application, after determining the target memory allocation mode that matches the current running time according to the corresponding relationship, the method further includes:
[0069] Determine the current memory allocation information corresponding to the target program under the running time; determine the target running time that matches the running time in the memory allocation information table; determine the target memory allocation information corresponding to the target running time; determine whether the current memory allocation information matches the target memory allocation information; if the current memory allocation information does not match the target memory allocation information, replace the target memory allocation information with the current memory allocation information to update the memory allocation method in the memory allocation information table.
[0070] The above embodiment provides a memory allocation scheme. However, in a specific usage scenario, when a user uses a target program, on the one hand, the target program will increase the data calculated as the time of use increases. On the other hand, different users use programs in different ways. For example, some users only use the program to perform simple calculations when using the target program. And some users use the program to perform more complex calculation tasks. It can be seen that even if the target program not only increases with time, the calculation parameters increase, but also because of the current processing tasks, the calculation parameters increase. Therefore, in order to better allocate memory to the target program, the embodiment of the present application also provides a memory allocation scheme.
[0071] Specifically, in an actual scenario, if the target program has been running for a certain period of time, and the system also allocates corresponding memory to the target program according to the time the target program is running, then these allocated memories are the target memory allocation information in the embodiment of the present application. If at this time, the target program performs a more complex task, the memory allocated by the system according to the running time of the target program may be insufficient. At this time, there is still memory left, and the system will supplement the memory for the program in order to avoid program crashes. It can be seen that at this time, the cpu still does calculations and scheduling to allocate memory for the target program. In other words, the new memory allocation scheme calculated by the cpu at this time can be understood as the current memory allocation information in the embodiment of the present application. Furthermore, in order to avoid the cpu needing to re-allocate memory for the target program every time, the embodiment of the present application can replace the target memory allocation information in the memory allocation information table with the current memory allocation information determined by the cpu this time. In this way, the next time the target program runs to the running time corresponding to the target memory allocation information, the system is equivalent to calling the memory allocation plan of the current memory allocation information to the target program, and the current memory allocation information can meet the current use of the target program. Even if the target program does not process complex tasks when it runs to this time next time, the memory of the memory allocation plan of the current memory allocation information only exceeds the memory requirements of the target program. When the memory capacity is sufficient, there are no other negative effects. Therefore, the problem of the system allocating memory to the target program again is solved.
[0072] In order to better implement the embodiment of the present application, in one embodiment of the present application, the memory allocation information includes memory allocation areas of different unit types and the number of memory allocation areas under each unit type;
[0073] Determine whether the current memory allocation information matches the target memory allocation information, including:
[0074] Determine whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same; if the number of types is the same, take the number of memory allocation areas corresponding to the current memory allocation information in each same memory allocation type as the first memory allocation area number and the number of memory allocation areas corresponding to the target memory allocation information as the second memory allocation area number, and determine whether each second memory allocation area number is greater than or equal to the corresponding first memory allocation area number; if each second memory allocation area number is greater than or equal to the corresponding first memory allocation area number, determine that the current memory allocation information matches the target memory allocation information; if at least one of the second memory allocation area numbers is less than the corresponding first memory allocation area number, determine that the current memory allocation information does not match the target memory allocation information.
[0075] The above embodiment provides a solution for replacing the current memory allocation information with the target memory allocation information. The present application embodiment also provides a more detailed solution. For details, please see Table 1.
[0076] Partition size Number of partitions 4 15 8 20 12 3 16 56 20 19 24 34 28 67 32 33
[0077] Table 1
[0078] Among them, the partition size in Table 1 is the memory allocation area of different unit types in the embodiment of the present application, and the number of partitions is the number of memory allocation areas under each unit type in the embodiment of the present application. In other words, the current memory allocation information and the target memory allocation information can both correspond to a memory allocation scheme similar to Table 1. Therefore, when it is necessary to determine whether the current memory allocation information matches the target memory allocation information, it can be determined whether the type of the partition size of the current memory allocation information and the target memory allocation information is the same. If the current memory allocation information includes a partition size of 32, and the target memory allocation information does not include a partition size of 32, the current memory allocation information does not match the target memory allocation information. However, if the partition size of the current memory allocation information and the target memory allocation information are the same, that is, the unit type is the same, then the next step is determined. At this time, the next step includes detecting whether the number of partitions of the current memory allocation information under the same unit is greater than the number of partitions of the target memory allocation information. If the number of partitions of the previous memory allocation information under the same unit is greater than the number of partitions of the target memory allocation information, it proves that the memory demand of the current target program is higher than the memory allocated by the memory allocation information table, and the system needs to be reallocated. Therefore, if the number of partitions in the previous memory allocation information under the same unit is greater than the number of partitions in the target memory allocation information, there is no match. Otherwise, there is a match.
[0079] In order to better implement the embodiment of the present application, in one embodiment of the present application, the target memory allocation information is replaced with the current memory allocation information, including:
[0080] The second memory allocation area quantity is replaced with the first memory allocation area quantity to update the memory allocation method in the memory allocation information table.
[0081] According to the above embodiment, there is a situation where the number of partitions of the previous memory allocation information is greater than the number of partitions of the target memory allocation information under the same unit. Therefore, if this situation occurs, the number of the second memory allocation area of the target memory allocation information is replaced with the number of the first memory allocation area of the current memory allocation information. For example: Taking Table 1 as an example, assuming that the number of partitions corresponding to the partition size of 4 in the target memory allocation information is 15, and the number of partitions corresponding to the partition size of 4 in the current memory allocation information is 20, then 15 can be replaced with 20.
[0082] In order to better implement the embodiment of the present application, in an embodiment of the present application, after determining whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same, the method further includes:
[0083] If the number of types is not the same, determine the memory allocation area of the target unit type that exists in the current memory allocation information and does not exist in the target memory allocation information and the corresponding number of the memory allocation area of the target unit type; add the memory allocation area of the target unit type and the corresponding number of the memory allocation area of the target unit type to the target memory allocation information to realize the update of the memory allocation method in the memory allocation information table.
[0084] The above embodiment provides a case where the partition sizes are different. If this case occurs, for example, there is a partition scheme with a partition size of 4 and a partition size of 4 corresponding to a partition number of 15 in the current memory allocation information. Assuming that there is no partition size of 4 in the target memory allocation information, the partition scheme with a partition size of 4 and a partition size of 4 corresponding to a partition number of 15 in the current memory allocation information are updated to the target memory allocation information.
[0085] In order to better implement the embodiment of the present application, in an embodiment of the present application, after determining whether there is a memory allocation information table in the target storage location, the following steps are included:
[0086] If the memory allocation information table does not exist in the target storage location, the preset dynamic memory allocation method is determined as the target memory allocation method that matches the current running time.
[0087] The above-mentioned embodiment also provides a scheme for setting up the memory allocation information table in advance and storing it. The embodiment of the present application also provides a scheme when the memory allocation information table is not set. If the memory allocation information table does not exist at the target storage location, the system can perform memory allocation for the target program at this time. At the same time, the system can also record the scheme for memory allocation for the target program at different running times of the target program, and establish a mapping relationship according to the corresponding memory allocation method at different running times of the target program, form the memory allocation information table, and store it. Among them, the scheme for memory allocation for the target program by the system can be the dynamic memory allocation method preset in this application to allocate memory for the target program, and the preset dynamic memory allocation method is not limited in the specific embodiment of the present application.
[0088] In order to better implement the memory allocation method in the embodiment of the present application, in addition to the memory allocation method, the embodiment of the present application also provides a memory allocation device, such as Figure 3 As shown, the device 300 includes:
[0089] The acquisition module 301 is used to acquire the current running time of the target program;
[0090] The allocation module 302 is used to allocate memory to the target program according to a default memory allocation method if the current running time is less than or equal to the target time threshold;
[0091] The allocation module 302 is further configured to determine a target memory allocation mode that matches the current runtime if the current runtime is greater than a target time threshold, and allocate memory to the target program in the target memory allocation mode.
[0092] The memory allocation device provided in the present application can first obtain the running time of the program through the acquisition module 301, and according to the running time of the program, the allocation module 302 uses different memory allocation schemes for the program, thereby realizing dynamic allocation of memory and improving memory allocation efficiency.
[0093] In some embodiments of the present application, the allocation module 302 is specifically used to:
[0094] Determine whether there is a memory allocation information table in the target storage location; the memory allocation information table stores the correspondence between different operating time and different memory allocation methods;
[0095] If a memory allocation information table exists in the target storage location, a target memory allocation method matching the current runtime is determined based on the memory allocation information table.
[0096] In some embodiments of the present application, the allocation module 302 is further configured to:
[0097] Determine the current memory allocation information corresponding to the target program under the running time;
[0098] Determine the target running time that the running time matches in the memory allocation information table;
[0099] Determine the target memory allocation information corresponding to the target runtime;
[0100] Determine whether the current memory allocation information matches the target memory allocation information;
[0101] If the current memory allocation information does not match the target memory allocation information, the target memory allocation information is replaced with the current memory allocation information to update the memory allocation method in the memory allocation information table.
[0102] In some embodiments of the present application, the memory allocation information includes memory allocation areas of different unit types and the number of memory allocation areas under each unit type. The allocation module 302 is further specifically used to:
[0103] Determine whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same;
[0104] If the number of types is the same, the number of memory allocation areas corresponding to the current memory allocation information in each of the same memory allocation types is taken as the first number of memory allocation areas and the number of memory allocation areas corresponding to the target memory allocation information is taken as the second number of memory allocation areas, and it is determined whether the number of each second memory allocation area is greater than or equal to the corresponding number of first memory allocation areas;
[0105] If the number of each second memory allocation area is greater than or equal to the number of the corresponding first memory allocation area, determining that the current memory allocation information matches the target memory allocation information;
[0106] If at least one of the second memory allocation area numbers is smaller than the corresponding first memory allocation area number, it is determined that the current memory allocation information does not match the target memory allocation information.
[0107] In some embodiments of the present application, the allocation module 302 is further configured to:
[0108] The second memory allocation area quantity is replaced with the first memory allocation area quantity to update the memory allocation method in the memory allocation information table.
[0109] In some embodiments of the present application, the allocation module 302 is further configured to:
[0110] If the number of types is not the same, determining the memory allocation area of the target unit type that exists in the current memory allocation information and does not exist in the target memory allocation information and the number of memory allocation areas corresponding to the target unit type;
[0111] The memory allocation area of the target unit type and the quantity corresponding to the memory allocation area of the target unit type are added to the target memory allocation information to update the memory allocation method in the memory allocation information table.
[0112] In some embodiments of the present application, the allocation module 302 is further configured to:
[0113] If the memory allocation information table does not exist in the target storage location, the preset dynamic memory allocation method is determined as the target memory allocation method that matches the current running time.
[0114] The present application also provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps in any one of the memory allocation methods in the present application. The terminal device integrates any one of the memory allocation methods provided in the present application, such as Figure 4 As shown, it shows a schematic diagram of the structure of the terminal device involved in the embodiment of the present application, specifically:
[0115] The terminal device may include one or more processing core processors 401, one or more computer-readable storage media memories 402, a power supply 403, an input unit 404 and other components. Those skilled in the art will appreciate that Figure 4 The terminal device structure shown in the figure does not constitute a limitation on the terminal device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0116] The processor 401 is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, the processor 401 executes various functions of the terminal device and processes data, thereby monitoring the terminal device as a whole. Optionally, the processor 401 may include one or more processing cores; the processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. Preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, the user interface and the application program, etc., and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0117] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0118] The terminal device also includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, power consumption management and other functions through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0119] The terminal device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0120] Although not shown, the terminal device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the terminal device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, such as:
[0121] Get the current running time of the target program;
[0122] If the current running time is less than or equal to the target time threshold, memory is allocated to the target program according to the default memory allocation method;
[0123] If the current running time is greater than the target time threshold, a target memory allocation method matching the current running time is determined, and memory is allocated to the target program using the target memory allocation method.
[0124] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0125] To this end, an embodiment of the present application provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any memory allocation method provided in the embodiment of the present application. For example, the computer program is loaded by a processor to execute the following steps:
[0126] Get the current running time of the target program;
[0127] If the current running time is less than or equal to the target time threshold, memory is allocated to the target program according to the default memory allocation method;
[0128] If the current running time is greater than the target time threshold, a target memory allocation method matching the current running time is determined, and memory is allocated to the target program using the target memory allocation method.
[0129] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.
[0130] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.
[0131] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0132] The above is a detailed introduction to a memory allocation method and device provided in an embodiment of the present application. Specific examples are used in this article 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 of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A memory allocation method, characterized in that: The method comprises: Get the current running time of the target program; If the current running time is less than or equal to the target time threshold, memory is allocated to the target program according to a default memory allocation method; If the current running time is greater than the target time threshold, a target memory allocation mode matching the current running time is determined, and memory is allocated to the target program using the target memory allocation mode.
2. The memory allocation method according to claim 1, characterized in that: The determining of a target memory allocation mode that matches the current running time includes: Determine whether there is a memory allocation information table in the target storage location; the memory allocation information table stores the correspondence between different operating time and different memory allocation modes; If the memory allocation information table exists in the target storage location, a target memory allocation mode matching the current running time is determined based on the memory allocation information table.
3. The memory allocation method according to claim 2, characterized in that: After determining the target memory allocation mode matching the current running time according to the corresponding relationship, the method further includes: Determine current memory allocation information corresponding to the target program under the running time; Determine the target running time that the running time matches in the memory allocation information table; Determine target memory allocation information corresponding to the target runtime; Determine whether the current memory allocation information matches the target memory allocation information; If the current memory allocation information does not match the target memory allocation information, the target memory allocation information is replaced with the current memory allocation information to update the memory allocation mode in the memory allocation information table.
4. The memory allocation method according to claim 3, characterized in that: The memory allocation information includes memory allocation areas of different unit types and the number of memory allocation areas under each unit type; The determining whether the current memory allocation information matches the target memory allocation information includes: Determine whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same; If the number of types is the same, taking the number of memory allocation areas corresponding to the current memory allocation information in each of the same memory allocation types as the first number of memory allocation areas and the number of memory allocation areas corresponding to the target memory allocation information as the second number of memory allocation areas, determine whether the numbers of each of the second memory allocation areas are greater than or equal to the corresponding number of the first memory allocation areas; If the number of each of the second memory allocation areas is greater than or equal to the number of the corresponding first memory allocation areas, determining that the current memory allocation information matches the target memory allocation information; If at least one of the second memory allocation area numbers is smaller than the corresponding first memory allocation area number, it is determined that the current memory allocation information does not match the target memory allocation information.
5. The memory allocation method according to claim 4, characterized in that: The replacing the target memory allocation information with the current memory allocation information comprises: The second memory allocation area quantity is replaced by the first memory allocation area quantity to update the memory allocation mode in the memory allocation information table.
6. The memory allocation method according to claim 4, characterized in that: After determining whether the number of types of memory allocation areas of the same unit type in the current memory allocation information and the target memory allocation information is the same, the method further includes: If the number of types is different, determining the memory allocation area of the target unit type that exists in the current memory allocation information and does not exist in the target memory allocation information and the number corresponding to the memory allocation area of the target unit type; The memory allocation area of the target unit type and the number corresponding to the memory allocation area of the target unit type are added to the target memory allocation information to update the memory allocation method in the memory allocation information table.
7. The memory allocation method according to claim 2, characterized in that: After determining whether there is a memory allocation information table in the target storage location, the method includes: If the memory allocation information table does not exist in the target storage location, the preset dynamic memory allocation mode is determined as the target memory allocation mode that matches the current running time.
8. A memory allocation device, characterized in that: The device comprises: The acquisition module is used to obtain the current running time of the target program; An allocation module, configured to allocate memory to the target program according to a default memory allocation method if the current running time is less than or equal to a target time threshold; The allocation module is also used to determine a target memory allocation mode that matches the current running time if the current running time is greater than the target time threshold, and allocate memory to the target program using the target memory allocation mode.
9. A terminal device, characterized in that: The terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the steps in the memory allocation method described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps in the memory allocation method according to any one of claims 1 to 7.
