CN-115421908-B - Memory allocation method and device and electronic equipment
Abstract
The embodiment of the application discloses a memory allocation method and device and electronic equipment. The method comprises the steps of responding to an instruction for distributing memory to an application program, obtaining memory demand corresponding to the instruction, and obtaining memory configuration from the rest of memory to the application program if the rest of memory in a pre-configured first memory area meets the memory demand, wherein addresses of the memory included in the first memory area are continuous. Therefore, under the condition that the first memory area with continuous addresses is preconfigured, and under the condition that the memory is required to be allocated for the application program, the memory allocation degree can be directly selected from the first memory area, so that the required memory can be allocated for the application program more quickly by utilizing the characteristic that the addresses of the memories in the first memory area are continuous.
Inventors
- LI PEIFENG
Assignees
- OPPO广东移动通信有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20220818
Claims (8)
- 1. The memory allocation method is characterized by comprising the following steps: Responding to an instruction for distributing memory for an application program, and acquiring the memory demand corresponding to the instruction, wherein the instruction is triggered when the application program is started; Detecting whether the memory demand is greater than a demand threshold, wherein if the average starting time of a target application program in the electronic equipment is greater than a time threshold, the demand threshold is configured to be a first demand threshold, and if the average starting time is not greater than the time threshold, the demand threshold is configured to be a second demand threshold, the second demand threshold is greater than the first demand threshold, and the target application program comprises an application program installed by the electronic equipment; If the memory demand is greater than the demand threshold, and the memory demand is met by the residual memory in a preconfigured first memory area, acquiring memory configuration from the residual memory to the application program, wherein the first memory area comprises continuous addresses of the memory; If the memory demand is not greater than the demand threshold, allocating memory to the application program from the idle memory outside the first memory area; the method comprises the steps of storing a specified type of memory page which is recovered from a non-active linked list into the first memory area, discarding the specified type of memory page which is recovered if the cache function is closed, wherein the cache function of the first memory area starts to be closed when memory is allocated to an application program in the first memory area, and moving the specified type of memory page into the active linked list if the memory function is not closed.
- 2. The method according to claim 1, wherein the method further comprises: and determining the closing duration of the cache function of the first memory area according to the application program.
- 3. The method of claim 2, wherein determining the duration of the cache function off of the first memory region according to the application program comprises: And determining the closing duration of the cache function of the first memory area according to the historical starting duration of the application program, wherein the closing duration is in direct proportion to the historical starting duration.
- 4. The method of claim 1, wherein if the remaining memory in the preconfigured first memory region meets the memory requirement, further comprising, prior to obtaining a memory configuration from the remaining memory to the application: Detecting whether idle memory of the electronic equipment meets the memory demand; And if the free memory does not meet the memory demand, executing the memory which is left in the first memory area and is preset to meet the memory demand, and acquiring memory configuration from the left memory to the application program.
- 5. The method according to claim 4, wherein the method further comprises: if the residual memory in the preconfigured first memory area does not meet the memory demand, executing memory reclamation to increase the idle memory; and after the memory recovery is executed, distributing memory from the idle memory to the application program.
- 6. A memory allocation apparatus, the apparatus comprising: The allocation demand determining unit is used for responding to an instruction for allocating memory for the application program and acquiring the memory demand corresponding to the instruction, wherein the instruction is triggered when the application program is started; The memory allocation unit is used for detecting whether the memory demand is greater than a demand threshold, wherein if the average starting time of a target application program in the electronic equipment is detected to be greater than a time threshold, the demand threshold is configured to be a first demand threshold, if the average starting time is detected to be not greater than the time threshold, the demand threshold is configured to be a second demand threshold, the second demand threshold is greater than the first demand threshold, the target application program comprises the application program installed by the electronic equipment, if the memory demand is greater than the demand threshold, and if the residual memory in a preconfigured first memory area meets the memory demand, the memory is acquired from the residual memory and is configured to the application program, wherein the address of the memory included in the first memory area is continuous, the first memory area is also used for caching the memory pages of the appointed type moved out from an inactive linked list, and the memory pages of the appointed type comprise clean pages; The memory allocation unit is further configured to allocate memory to the application program from the idle memory outside the first memory area if the memory demand is not greater than the demand threshold; The memory page caching unit is used for responding to recovery of the pages of the specified types from the inactive linked list, detecting whether the first memory area closes the caching function or not, storing the pages of the specified types subjected to recovery into the first memory area if the caching function is not closed, discarding the pages of the specified types subjected to recovery if the caching function is closed, wherein the caching function of the first memory area starts to be closed when the memory in the first memory area is distributed to an application program, and moving the pages of the specified types into the active linked list if the pages of the specified types are read during the period that the pages of the specified types are stored in the first memory area.
- 7. An electronic device comprising one or more processors and a memory, one or more programs stored in the memory and configured to perform the method of any of claims 1-5 by the one or more processors.
- 8. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein a program code, wherein the program code, when being executed by a processor, performs the method of any of claims 1-5.
Description
Memory allocation method and device and electronic equipment Technical Field The present application relates to the field of computer technologies, and in particular, to a memory allocation method, apparatus, and electronic device. Background The memory is also called as main memory, is a memory space which can be directly addressed by a CPU and is made of a semiconductor device. Applications in electronic devices typically require memory to perform data processing during operation. However, the allocation efficiency of the related memory allocation method needs to be improved. Disclosure of Invention In view of the above, the present application provides a memory allocation method, apparatus and electronic device, so as to improve the above problem. The application provides a memory allocation method which is characterized by comprising the steps of responding to an instruction for allocating memory for an application program, obtaining memory demand corresponding to the instruction, and obtaining memory allocation from the residual memory to the application program if the residual memory in a pre-allocated first memory area meets the memory demand, wherein addresses of the memory included in the first memory area are continuous. The application provides a memory allocation device which is characterized by comprising an allocation requirement determining unit and a memory allocation unit, wherein the allocation requirement determining unit is used for responding to an instruction for allocating memory for an application program and obtaining the memory requirement corresponding to the instruction, the memory allocation unit is used for obtaining memory allocation from the residual memory to the application program if the residual memory in a pre-allocated first memory area meets the memory requirement, and the addresses of the memory included in the first memory area are continuous. In a third aspect, the application provides an electronic device comprising one or more processors and a memory, one or more programs stored in the memory and configured to be executed by the one or more processors to implement the method described above. In a fourth aspect, the present application provides a computer readable storage medium having program code stored therein, wherein the program code, when executed by a processor, performs the method described above. According to the memory allocation method, the memory allocation device and the electronic equipment provided by the application, after the memory demand corresponding to the instruction is obtained in response to the instruction for allocating the memory for the application program, the memory allocation for the application program can be obtained from the residual memory under the condition that the residual memory in the preconfigured first memory area with continuous memory addresses meets the memory demand. Therefore, under the condition that the first memory area with continuous addresses is preconfigured, and under the condition that the memory is required to be allocated for the application program, the memory allocation degree can be directly selected from the first memory area, so that the required memory can be allocated for the application program more quickly by utilizing the characteristic that the addresses of the memories in the first memory area are continuous. Drawings In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. Fig. 1 shows a flowchart of a memory allocation method according to an embodiment of the present application; FIG. 2 is a schematic diagram of a first memory region according to an embodiment of the present application; fig. 3 is a flowchart illustrating a memory allocation method according to still another embodiment of the present application; FIG. 4 is a schematic diagram illustrating selecting memory from a first memory area for allocation to an application program according to an embodiment of the present application; fig. 5 is a flowchart illustrating a memory allocation method according to still another embodiment of the present application; fig. 6 is a flowchart illustrating a memory allocation method according to still another embodiment of the present application; Fig. 7 is a block diagram illustrating a memory allocation apparatus according to an embodiment of the present application; fig. 8 shows a block diagram of an electronic device for executing a memory allocation method according to an embodiment of the present application in real time; fig. 9 shows a storage unit for storing or carrying program codes for implementing a m