WO2024067348A2 - 内存分配器确定方法、装置、电子设备及存储介质 - Google Patents
内存分配器确定方法、装置、电子设备及存储介质 Download PDFInfo
- Publication number
- WO2024067348A2 WO2024067348A2 PCT/CN2023/120413 CN2023120413W WO2024067348A2 WO 2024067348 A2 WO2024067348 A2 WO 2024067348A2 CN 2023120413 W CN2023120413 W CN 2023120413W WO 2024067348 A2 WO2024067348 A2 WO 2024067348A2
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- memory
- memory allocator
- electronic device
- target
- allocator
- Prior art date
Links
- 230000015654 memory Effects 0.000 title claims abstract description 489
- 238000000034 method Methods 0.000 title claims abstract description 396
- 230000008569 process Effects 0.000 claims abstract description 335
- 230000006870 function Effects 0.000 claims description 50
- 238000012360 testing method Methods 0.000 claims description 21
- 238000012545 processing Methods 0.000 claims description 16
- 238000004891 communication Methods 0.000 claims description 8
- 238000004590 computer program Methods 0.000 claims description 4
- FFBHFFJDDLITSX-UHFFFAOYSA-N benzyl N-[2-hydroxy-4-(3-oxomorpholin-4-yl)phenyl]carbamate Chemical compound OC1=C(NC(=O)OCC2=CC=CC=C2)C=CC(=C1)N1CCOCC1=O FFBHFFJDDLITSX-UHFFFAOYSA-N 0.000 description 21
- 238000012549 training Methods 0.000 description 7
- 238000010586 diagram Methods 0.000 description 6
- 230000000694 effects Effects 0.000 description 5
- 230000001360 synchronised effect Effects 0.000 description 4
- 230000003190 augmentative effect Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 1
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 1
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 1
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 1
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 1
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 1
- 239000003795 chemical substances by application Substances 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000007599 discharging Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000013102 re-test Methods 0.000 description 1
- 230000004044 response Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5018—Thread allocation
Definitions
- the present application belongs to the field of communication technology, and specifically relates to a method, device, electronic device and storage medium for determining a memory allocator.
- the operating system of an electronic device can only include one memory allocator (eg, memory allocator 1) to be responsible for memory allocation and management of the electronic device, so that all processes running on the electronic device use memory allocator 1.
- memory allocator 1 e.g, memory allocator 1
- process 1 uses memory allocator 1
- the memory usage is small and the process performance is poor; however, since the application corresponding to process 1 is an important application in the electronic device, it has high requirements for process performance and low requirements for memory usage, so process 1 is not suitable for using memory allocator 1; thus, the electronic device has low flexibility in using memory allocators.
- the purpose of the embodiments of the present application is to provide a method, device, electronic device and storage medium for determining a memory allocator, which can solve the problem of low flexibility in using a memory allocator in an electronic device.
- an embodiment of the present application provides a memory allocator determination method, which includes: obtaining information of a first process running in an electronic device; based on the information of the first process, determining a target memory allocator from at least two memory allocators compatible with the electronic device; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- an embodiment of the present application provides a memory allocator determination device, the memory allocator determination device comprising: an acquisition module and a determination module.
- the acquisition module is used to acquire information of a first process running in an electronic device.
- the determination module is used to determine a target memory allocator from at least two memory allocators compatible with the electronic device based on the information of the first process acquired by the acquisition module; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.
- an embodiment of the present application provides a readable storage medium, wherein the readable storage medium stores a program A program or instruction, when the program or instruction is executed by a processor, implements the steps of the method described in the first aspect.
- an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.
- an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the first aspect.
- the electronic device can obtain information about a first process running in the electronic device; and determine a target memory allocator from at least two memory allocators compatible with the electronic device based on the information about the first process; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- the electronic device can obtain information about the first process running in the electronic device, the electronic device can determine a target content allocator that matches the first process from at least two compatible content allocators based on the obtained information about the first process, that is, the electronic device can select a memory allocator suitable for the first process as the target memory allocator to manage the memory of the first process, thereby improving the flexibility of the electronic device in using the memory allocator.
- FIG1 is a schematic diagram of a flow chart of a method for determining a memory allocator provided in an embodiment of the present application
- FIG2 is a schematic diagram of the structure of a memory allocator determination device provided in an embodiment of the present application.
- FIG3 is a schematic diagram of a hardware structure of an electronic device provided in an embodiment of the present application.
- FIG. 4 is a second schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.
- first, second, etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first”, “second”, etc. are generally of one type, and the number of objects is not limited.
- the first object can be one or more.
- “and/or” in the specification and claims represents at least one of the connected objects, and the character “/" generally indicates that the objects associated with each other are in an "or” relationship.
- the memory allocator determination method in the embodiment of the present application can be applied to a scenario where an electronic device uses a memory allocator.
- the operating system of electronic devices can manage the memory application of user state through a memory allocator.
- the memory allocator acts as an agent for the user process to apply for and release memory through malloc function, calloc function, free function, etc.
- the memory allocators used by electronic devices are mainly Jemalloc memory allocators or Scudo memory allocators. That is to say, the operating system of an electronic device can only include one memory allocator (for example: Jemalloc memory allocator) to be responsible for the memory allocation and management of the electronic device. Therefore, the processes running on the electronic device are also processed using the Jemalloc memory allocator.
- the present application provides a method for an operating system to support multiple memory allocators, which is intended to enable most processes running on the operating system to use a memory allocator that is more suitable for the business logic of the process itself.
- the electronic device can obtain information about the first process running in the electronic device; and determine a target memory allocator from at least two memory allocators compatible with the electronic device based on the information about the first process; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- the electronic device can obtain information about the first process running in the electronic device, the electronic device can determine a target content allocator that matches the first process from at least two compatible content allocators based on the obtained information about the first process, that is, the electronic device can select a memory allocator suitable for the first process as the target memory allocator to manage the memory of the first process, thereby improving the flexibility of the electronic device in using the memory allocator.
- the present application embodiment provides a memory allocator determination method
- Figure 1 shows a flowchart of a memory allocator determination method provided by the present application embodiment, which can be applied to electronic devices.
- the memory allocator determination method provided by the present application embodiment may include the following steps 201 and 202.
- Step 201 The electronic device obtains information of a first process running in the electronic device.
- the first process may be a process corresponding to any application in the electronic device.
- the information of the first process may be an identifier of the first process, and the identifier of the first process may be understood as an identifier of an application corresponding to the first process.
- Step 202 The electronic device determines a target memory allocator from at least two memory allocators compatible with the electronic device based on information from the first process.
- the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- the electronic device can search for a target memory allocator that matches the first process from at least two memory allocators compatible with the electronic device based on information of the first process, so as to use the target memory allocator to manage the memory of the first process after determining the target memory allocator.
- the target memory allocator is the memory allocator that works best for running the first process.
- the memory allocator determination method provided in the embodiment of the present application also includes the following step 301.
- Step 301 The electronic device modifies the original compilation condition to obtain the target compilation condition.
- the electronic device under the original compilation condition, supports one memory allocator; under the target compilation condition, the electronic device is compatible with at least two memory allocators.
- the above-mentioned modification to the original compilation conditions is a modification to a Makefile script file
- the Makefile script file is used to control the compilation content
- the electronic device may be compatible with at least two memory allocators through a standard function library (Libc) or other function libraries capable of storing memory allocators.
- Libc standard function library
- other function libraries capable of storing memory allocators.
- the memory allocator compatible with the electronic device may be at least two of the following: Scudo Memory allocator, Jemalloc-4.1.0 memory allocator, Jemalloc-5.1.0 memory allocator.
- step 202 can be specifically implemented by the following steps 202a to 202c.
- Step 202a The electronic device calls the first interface according to the information of the first process.
- the above-mentioned first interface is implemented by functions related to memory allocation.
- the first interface may be a memory allocation interface or a memory release interface.
- the above-mentioned memory allocation interface can be implemented by: malloc function, calloc function or realloc function, or by other functions responsible for memory allocation.
- the specific function can be determined according to actual usage requirements and is not limited by the embodiment of the present invention.
- the above-mentioned memory release interface can be implemented by a free function, or by other functions responsible for memory release.
- the specific function can be determined according to actual usage requirements and is not limited by the embodiment of the present invention.
- the above-mentioned first interface is a public interface, or can be understood as an interface that can be directly called by a process.
- Step 202b The electronic device calls the second interface through the first interface.
- the above-mentioned second interface is implemented by a function of searching the memory allocator.
- the second interface is an intermediate layer interface added between the first interface and the memory allocator interface, and the second interface is an interface corresponding to the operating system of the electronic device.
- the above-mentioned second interface can be implemented by a vendor_malloc function, a vendor_calloc function, a vendor_realloc function or a vendor_free function, or by other functions that have the function of searching for a memory allocator.
- the specific function can be determined based on actual usage requirements and is not limited by the embodiment of the present invention.
- the electronic device calling the second interface through the first interface can be understood as: when the electronic device calls the first interface, it is redirected or connected to the second interface to select a memory allocator for the first process through the second interface.
- the second interface is an interface corresponding to the first interface.
- the second interface called through the first interface is an interface corresponding to the first interface (for example, an interface implemented by the vendor_calloc function); or, when the first interface called by the electronic device is a memory release interface (for example, an interface implemented by the free function), the second interface called through the first interface is an interface corresponding to the first interface (for example, an interface implemented by the vendor_free function).
- Step 202c The electronic device determines a target memory allocator from at least two memory allocators compatible with the electronic device through the second interface.
- the electronic device when the electronic device is compatible with multiple memory allocators, the electronic device can determine a memory allocator suitable for the first process from the multiple memory allocators through the second interface to manage the memory of the first process.
- the first interface is a memory allocation interface, and the target memory allocator is used to allocate memory to the first process.
- the first interface is a memory release interface, and the target memory allocator is used to release the memory of the first process.
- the electronic device calls the second interface corresponding to the memory allocation interface through the first interface, and then the second interface determines the target memory allocator corresponding to the first process, and then allocates memory to the first process through the target memory allocator interface responsible for allocating memory corresponding to the first interface.
- the second interface called by the electronic device through the first interface is an interface implemented by the vendor_malloc function
- the second interface determines that the target memory allocator is the Scudo memory allocator memory can be allocated to the first process through the interface implemented by the Scudo-malloc function.
- the electronic device calls the second interface corresponding to the memory release interface through the first interface, and then the second interface determines the target memory allocator corresponding to the first process, and then releases memory for the first process through the target memory allocator interface responsible for releasing memory corresponding to the first interface.
- the second interface called by the electronic device through the first interface is an interface implemented by the vendor_free function, and then after the second interface determines that the target memory allocator is the Jemalloc memory allocator, memory can be released for the first process through the interface implemented by the Jemalloc-free function.
- the embodiment of the present application provides a memory allocator determination method, where an electronic device can obtain information about a first process running in the electronic device; and based on the information about the first process, a target memory allocator is determined from at least two memory allocators compatible with the electronic device; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- the electronic device can obtain information about the first process running in the electronic device, the electronic device can determine a target content allocator that matches the first process from at least two compatible content allocators based on the obtained information about the first process, that is, the electronic device can select a memory allocator suitable for use by the first process as the target memory allocator to manage the memory of the first process, thereby improving the flexibility of the electronic device in using the memory allocator.
- the electronic device determines a target memory allocator from at least two memory allocators compatible with the electronic device can be specifically implemented through the following steps 401 and 402.
- Step 401 The electronic device obtains a target result table.
- the above-mentioned target result table is used to indicate the correspondence between the process and the memory allocator.
- the target result table includes at least one corresponding relationship, and each corresponding relationship is a corresponding relationship between a process and a memory allocator.
- Step 402 When the target result table contains information about the first process, the electronic device determines the memory allocator corresponding to the information about the first process in the target result table as the target memory allocator.
- the electronic device can test the first process through at least two memory allocators to determine the memory allocator corresponding to the first process and add it to the target result table, so that the information of the first process exists in the target result table. That is, the target result table stores the correspondence between each process and its most suitable memory allocator.
- the electronic device may obtain a target result table, and search the target result table for a memory allocator corresponding to the first process according to information of the first process, so as to determine a target memory allocator.
- the electronic device may search for the first process in the target result table through the second interface according to the information of the first process, and determine the memory allocator corresponding to the first process as the target memory allocator.
- the table includes the identifiers of processes 1 to 5, and the memory allocator corresponding to each process, that is, it includes 5 corresponding relationships; the electronic device can search for process 3 in the target result table through the second interface based on the information of the first process (for example: process 3), and determine the memory allocator corresponding to process 3 (for example: process 3 corresponds to memory allocator 2) as the target memory allocator, so as to manage the memory of process 3 through the memory allocator 2.
- the electronic device when the electronic device is running the first process and calling the first interface implemented by the function related to memory allocation, it can call the second interface implemented by the function of searching the memory allocator through the first interface, so as to search the target memory allocator corresponding to the first process in the target result table through the second interface, so as to manage the memory of the first process through the target memory allocator, thereby improving the flexibility of the electronic device in using the memory allocator.
- the electronic device determines a target memory allocator from at least two memory allocators compatible with the electronic device" in the above step 202 can be specifically implemented through the following step 501.
- Step 501 When it is determined based on information of the first process that the first process is not being run for the first time, the electronic device obtains the value of the global variable of the first process and determines the memory allocator corresponding to the value of the global variable of the first process as the target memory allocator.
- the value of a global variable corresponds to a memory allocator.
- each process corresponds to a global variable (flag).
- the electronic device may set in advance a correspondence between each memory allocator and a numerical value of a global variable according to at least two memory allocators that the electronic device is compatible with.
- the value of the global variable corresponding to memory allocator 1 is 1; the value of the global variable corresponding to memory allocator 2 is 2; the value of the global variable corresponding to memory allocator 3 is 3. That is, when the flag value is 1, it indicates memory allocator 1, when the flag value is 2, it indicates memory allocator 2, and when the flag value is 3, it indicates memory allocator 3.
- the electronic device can read the value of the global variable of the first process from the value of at least one global variable through the second interface based on the information of the first process, thereby determining the memory allocator corresponding to the value of the global variable of the first process as the target memory allocator.
- the memory allocator for example, memory allocator 2
- the electronic device can obtain the value of the global variable of the first process through the second interface, and determine the memory allocator corresponding to the value of the global variable of the first process as the target memory allocator to manage the memory of the first process, the flexibility of the electronic device in using the memory allocator is improved.
- the memory allocator determination method provided in the embodiment of the present application also includes the following step 601.
- Step 601 The electronic device updates the value of the global variable corresponding to each process in the target result table according to the target result table.
- the values of different global variables correspond to different memory allocators, and the target result table is used to indicate the corresponding relationship between the process and the memory allocator.
- the electronic device may update the values of global variables corresponding to each process in the target result table based on the correspondence between the memory allocator and the values of the global variables.
- the value of the global variable corresponding to the first process can be updated according to the correspondence between the memory allocator and the value of the global variable; so that when the electronic device runs the first process again, the value of the global variable of the first process can be directly obtained to determine the memory allocator corresponding to the value of the global variable of the first process as the target memory allocator.
- the electronic device does not need to search the target result table every time to determine the memory allocator corresponding to the first process, thereby reducing the time consumption of the electronic device.
- the electronic device updates the value of the global variable corresponding to each process in the target result table, which can be understood as initializing the value of the global variable of each process.
- the value of the global variable of each process is not initialized, the value is 0.
- the memory allocator determination method provided in the embodiment of the present application also includes the following steps 701 to 703.
- Step 701 When there is no test data related to the first process in the electronic device, the electronic device tests the first process in the electronic device through at least two memory allocators to obtain the score of the first process when using each memory allocator.
- the electronic device may test a first process in the electronic device through at least two memory allocators to obtain a performance score and a memory score when the first process uses each memory allocator.
- the electronic device can test the process startup time, process key flow time, etc. when the first process uses at least two memory allocators through a process training model to obtain a performance score when the first process uses each memory allocator.
- the electronic device can use a process training model to test the process startup memory occupancy when the first process uses at least two memory allocators, the process memory occupancy peak, the memory occupancy when the process resides in the background, etc., to obtain the memory score when the first process uses each memory allocator.
- the electronic device may determine the score of the first process when using each memory allocator based on the performance score and memory score of the first process when using each memory allocator, the process performance weight of the first process, and the system memory weight of the electronic device.
- the process performance weight of the above-mentioned first process can be set by the user according to the importance of the process.
- the system memory weight of the above-mentioned electronic device may be determined according to the memory of the electronic device.
- the electronic device can set a higher system memory weight to ensure that the electronic device has sufficient memory; and for an electronic device with a larger memory (for example, the memory is greater than a threshold), since the memory allocated to the process is more sufficient, the electronic device can set a lower system memory weight to improve the performance of the electronic device.
- process 1 can test the performance score and memory score of process 1 when using memory allocator 1 through a process training model, and then determine the score of process 1 when using memory allocator 1 based on the performance score and memory score of process 1 when using memory allocator 1, as well as the process performance weight of process 1 set by the user and the system memory weight of the electronic device; and can test the performance score and memory score of process 1 when using memory allocator 2 through a process training model, and then determine the score of process 1 when using memory allocator 2 based on the performance score and memory score of process 1 when using memory allocator 2, as well as the process performance weight of process 1 set by the user and the system memory weight of the electronic device; and can test the performance score and memory score of process 1 when using memory allocator 3 through a process training model, and then determine the score of process 1 when using memory allocator 3 based on the performance score and memory score of process
- the electronic device may calculate the score of each memory allocator used by the first process by using the following formula:
- Total score (total_score) process performance weight (process_perf_weight_coefficient) * performance score (perf_score) + system memory weight (sys_mem_weight_coefficient) * memory score (mem_score).
- process 1 uses memory allocator 1
- its performance score is 6 points and its memory score is 8 points.
- the process performance weight of process 1 is 1 and the system memory weight of the electronic device is 2.
- Step 702 The electronic device determines the memory allocator corresponding to the maximum score among multiple scores as the target memory allocator corresponding to the first process.
- the electronic device can determine the memory allocator corresponding to the largest score among the multiple scores as the target memory allocator corresponding to the first process.
- Step 703 The electronic device associates the first process with the target memory allocator corresponding to the first process, and adds the associated process to the target result table.
- the subsequent electronic device runs the first process, it can determine the target memory allocator corresponding to the first process according to the target result table, and manage the memory of the first process through the target memory allocator, thereby improving the accuracy of the electronic device using the memory allocator.
- the above-mentioned target result table includes an identifier of at least one process and an identifier of at least one memory allocator, and each memory allocator corresponds to a process.
- some processes in the electronic device are non-key processes, and their performance and memory usage do not differ much when using different allocators, so they do not need to participate in the test and the default allocator of the electronic device is used to manage memory, which may be any one of at least two memory allocators compatible with the electronic device.
- the target result table can be updated as the system version of the electronic device is updated. It is understandable that when the system of the electronic device is updated, the electronic device can retest the process in the electronic device through at least two memory allocators to update the target result table according to the test results.
- the memory allocator determination method provided in the embodiment of the present application may also include the following steps 801 to 803.
- Step 801 The electronic device displays a target setting interface.
- the above-mentioned target setting interface includes the identifier of at least one process and the identifier of at least one memory allocator, and each memory allocator corresponds to a process.
- the electronic device may provide a function for setting a process memory allocator in a setting interface or a housekeeper application, and the user may input to trigger the electronic device to display an interface for setting a process memory allocator (i.e., a target setting interface).
- a process memory allocator i.e., a target setting interface
- Step 802 The electronic device receives a first input from a user.
- the above-mentioned first input is an input used to modify the memory allocator corresponding to the target process.
- the target process may be a trained process or an untrained process.
- the above-mentioned target setting interface may include a first control, and the first control is used to trigger the electronic device to train a target process.
- the above-mentioned first input can be a touch input (for example, a click input, a drag input, or a sliding input, etc.) or other feasible input by the user to the above-mentioned first control, so as to trigger the electronic device to modify the memory allocator corresponding to the target process, and update the identifier of the memory allocator corresponding to the target process in the target setting interface.
- a touch input for example, a click input, a drag input, or a sliding input, etc.
- other feasible input by the user to the above-mentioned first control so as to trigger the electronic device to modify the memory allocator corresponding to the target process, and update the identifier of the memory allocator corresponding to the target process in the target setting interface.
- the embodiment of the present application is not limited to this.
- Step 803 The electronic device modifies the memory allocator corresponding to the target process in response to the first input, and updates the identifier of the memory allocator corresponding to the target process in the target setting interface.
- the electronic device trains the target process, it can simultaneously update the target process.
- the memory allocator determination method provided in the embodiment of the present application can be executed by an electronic device, or a memory allocator determination device, or a control module in the memory allocator determination device.
- an electronic device executing the memory allocator determination method is taken as an example to illustrate the memory allocator determination device provided in the embodiment of the present application.
- Fig. 2 shows a possible structural diagram of a memory allocator determination device involved in an embodiment of the present application.
- the memory allocator determination device 70 may include: an acquisition module 71 and a determination module 72 .
- the acquisition module 71 is used to acquire information of a first process running in the electronic device.
- the determination module 72 is used to determine a target memory allocator from at least two memory allocators compatible with the electronic device according to the information of the first process acquired by the acquisition module 71; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- An embodiment of the present application provides a memory allocator determination device. Since the electronic device can obtain information about a first process running in the electronic device, the electronic device can determine a target content allocator that matches the first process from at least two compatible content allocators based on the obtained information about the first process. That is, the electronic device can select a memory allocator suitable for the first process as the target memory allocator to manage the memory of the first process, thereby improving the flexibility of the electronic device in using the memory allocator.
- the memory allocator determination device 70 provided in the embodiment of the present application further includes: a processing module.
- the processing module is used to call the first interface according to the information of the first process, and the first interface is implemented by a function related to memory allocation; and call the second interface through the first interface, and the second interface is implemented by a function for searching for a memory allocator.
- the determination module 72 is specifically used to determine the target memory allocator from at least two memory allocators compatible with the electronic device through the second interface.
- the acquisition module 71 is further used to acquire a target result table, which is used to indicate the correspondence between processes and memory allocators.
- the determination module is specifically used to determine the memory allocator corresponding to the information of the first process in the target result table as the target memory allocator when there is information of the first process in the target result table.
- the acquisition module 71 is further used to acquire the value of the global variable of the first process when it is determined that the first process is not running for the first time based on the information of the first process.
- the determination module is specifically used to determine the memory allocator corresponding to the value of the global variable of the first process as the target memory allocator, and one global variable value corresponds to one memory allocator.
- the memory allocator determination device 70 provided in the embodiment of the present application further includes: an update module.
- the update module is used to update the value of the global variable corresponding to each process in the target result table according to the target result table before the acquisition module 71 acquires the value of the global variable of the first process, wherein different values of the global variables correspond to different memory allocators, and the target result table is used to indicate the corresponding relationship between the process and the memory allocator.
- the memory allocator determination device 70 provided in the embodiment of the present application also includes: a processing module.
- the processing module is used to test the first process in the electronic device through at least two memory allocators before the acquisition module 71 acquires the information of the first process running in the electronic device, and obtain the score of the first process when using each memory allocator respectively, when there is no test data related to the first process in the electronic device.
- the determination module 72 is also used to determine the memory allocator corresponding to the maximum score among multiple scores as the target memory allocator corresponding to the first process.
- the processing module is also used to associate the first process with the target memory allocator corresponding to the first process, And added to the target results table.
- the memory allocator determination device 70 provided in the embodiment of the present application further includes: a processing module.
- the processing module is used to modify the original compilation condition to obtain the target compilation condition before the determination module 72 determines the target memory allocator from at least two memory allocators compatible with the electronic device according to the information of the first process; wherein, under the original compilation condition, the electronic device supports one memory allocator; under the target compilation condition, the electronic device is compatible with at least two memory allocators.
- the first interface is a memory allocation interface, and the target memory allocator is used to allocate memory to the first process; or, the first interface is a memory release interface, and the target memory allocator is used to release the memory of the first process.
- the memory allocator determination device in the embodiment of the present application can be a device, or a component, integrated circuit, or chip in an electronic device.
- the device can be a mobile electronic device or a non-mobile electronic device.
- the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a car-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc.
- NAS Network Attached Storage
- PC personal computer
- TV television
- teller machine a self-service machine
- the memory allocator determination device in the embodiment of the present application may be a device having an operating system.
- the operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
- the memory allocator determination device provided in the embodiment of the present application can implement each process implemented in the above method embodiment. To avoid repetition, it will not be repeated here.
- an embodiment of the present application also provides an electronic device 900, including a processor 901 and a memory 902, and the memory 902 stores a program or instruction that can be executed on the processor 901.
- the program or instruction is executed by the processor 901
- the various steps of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
- the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
- FIG. 4 is a schematic diagram of the hardware structure of an electronic device implementing an embodiment of the present application.
- the electronic device 100 includes but is not limited to components such as a radio frequency unit 101, a network module 102, an audio output unit 103, an input unit 104, a sensor 105, a display unit 106, a user input unit 107, an interface unit 108, a memory 109, and a processor 110.
- components such as a radio frequency unit 101, a network module 102, an audio output unit 103, an input unit 104, a sensor 105, a display unit 106, a user input unit 107, an interface unit 108, a memory 109, and a processor 110.
- the electronic device 100 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 110 through a power management system, so that the power management system can manage charging, discharging, and power consumption.
- a power source such as a battery
- the electronic device structure shown in FIG4 does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown, or combine certain components, or arrange components differently, which will not be described in detail here.
- the processor 110 is used to obtain information about a first process running in the electronic device; and based on the information of the first process, determine a target memory allocator from at least two memory allocators compatible with the electronic device; wherein the target memory allocator is used to manage the memory of the first process, and the target memory allocator matches the first process.
- An embodiment of the present application provides an electronic device. Since the electronic device can obtain information about a first process running in the electronic device, the electronic device can determine a target content allocator that matches the first process from at least two compatible content allocators based on the obtained information about the first process, that is, the electronic device can select a memory allocator suitable for the first process as the target memory allocator to manage the memory of the first process, thereby improving the flexibility of the electronic device in using the memory allocator.
- the processor 110 is further used to call a first interface according to information of the first process, the first interface being implemented by functions related to memory allocation; and to call a second interface through the first interface, the second interface being implemented by a function for searching a memory allocator.
- the processor 110 is specifically configured to determine, through the second interface, a target memory allocator from at least two memory allocators compatible with the electronic device.
- the processor 110 is further configured to obtain a target result table, where the target result table is used to indicate a correspondence between a process and a memory allocator.
- the processor 110 is specifically configured to determine, when there is information of the first process in the target result table, a memory allocator corresponding to the information of the first process in the target result table as a target memory allocator.
- the processor 110 is further configured to obtain a value of a global variable of the first process when it is determined, based on the information of the first process, that the first process is not being run for the first time.
- the processor 110 is specifically configured to determine the memory allocator corresponding to the value of the global variable of the first process as the target memory allocator, and one value of the global variable corresponds to one memory allocator.
- the processor 110 is also used to update the value of the global variable corresponding to each process in the target result table according to the target result table before obtaining the value of the global variable of the first process, wherein different values of the global variables correspond to different memory allocators, and the target result table is used to indicate the correspondence between the process and the memory allocator.
- the processor 110 is further used to test the first process in the electronic device through at least two memory allocators before obtaining information about the first process running in the electronic device, in the absence of test data related to the first process in the electronic device, to obtain scores of the first process when using each memory allocator; and determine the memory allocator corresponding to the maximum score among multiple scores as the target memory allocator corresponding to the first process; and associate the first process with the target memory allocator corresponding to the first process, and add it to the target result table.
- the processor 110 is also used to modify the original compilation condition to obtain the target compilation condition before determining the target memory allocator from at least two memory allocators compatible with the electronic device based on the information of the first process; wherein, under the original compilation condition, the electronic device supports one memory allocator; under the target compilation condition, the electronic device is compatible with at least two memory allocators.
- the electronic device provided in the embodiment of the present application can implement each process implemented in the above method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described here.
- the input unit 104 may include a graphics processing unit (GPU) 1041 and a microphone 1042, and the graphics processor 1041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode.
- the display unit 106 may include a display panel 1061, which may be configured in the form of a liquid crystal display, an organic light emitting diode, etc.
- the user input unit 107 includes at least one of a touch panel 1071 and other input devices 1072. Touch panel 1071, also called a touch screen.
- the touch panel 1071 may include two parts: a touch detection device and a touch controller.
- Other input devices 1072 may include, but are not limited to, a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, and a joystick, which will not be described in detail here.
- the memory 109 can be used to store software programs and various data.
- the memory 109 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc.
- the memory 109 may include a volatile memory or a non-volatile memory, or the memory 109 may include both volatile and non-volatile memories.
- the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory.
- the volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM).
- the memory 109 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
- the processor 110 may include one or more processing units; optionally, the processor 110 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 110.
- An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored.
- a program or instruction is stored.
- the various processes of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
- the processor is the processor in the electronic device described in the above embodiment.
- the readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
- An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
- the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
- An embodiment of the present application provides a computer program product, which is stored in a storage medium.
- the program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
- the technical solution of the present application can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM/RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
- a storage medium such as ROM/RAM, a disk, or an optical disk
- a terminal which can be a mobile phone, a computer, a server, or a network device, etc.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Techniques For Improving Reliability Of Storages (AREA)
- Hardware Redundancy (AREA)
Abstract
本申请公开了一种内存分配器确定方法、装置、电子设备及存储介质,该方法包括:获取在电子设备中运行的第一进程的信息;根据该第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,该目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。
Description
相关申请的交叉引用
本申请主张在2022年09月28日在中国提交的申请号为202211190505.X的中国专利的优先权,其全部内容通过引用包含于此。
本申请属于通信技术领域,具体涉及一种内存分配器确定方法、装置、电子设备及存储介质。
目前,电子设备的操作系统(例如安卓(Android)系统)只能包含一种内存分配器(例如:内存分配器1),以负责电子设备的内存分配与管理,使得电子设备上运行的进程都使用内存分配器1。
然而,由于不同的内存分配器的机制存在差异,因此电子设备上运行的部分进程并不适合使用内存分配器1。例如:进程1使用内存分配器1时,内存占用较少、进程性能较差;但是由于进程1对应的应用程序为电子设备中的重要应用程序,对进程性能要求较高,内存占用要求较低,所以进程1并不适合使用内存分配器1;如此,电子设备使用内存分配器的灵活性较低。
发明内容
本申请实施例的目的是提供一种内存分配器确定方法、装置、电子设备及存储介质,能够解决电子设备使用内存分配器的灵活性较低的问题。
为了解决上述技术问题,本申请是这样实现的:
第一方面,本申请实施例提供了一种内存分配器确定方法,该内存分配器确定方法包括:获取在电子设备中运行的第一进程的信息;根据该第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,该目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。
第二方面,本申请实施例提供了一种内存分配器确定装置,该内存分配器确定装置包括:获取模块和确定模块。获取模块,用于获取在电子设备中运行的第一进程的信息。确定模块,用于根据获取模块获取的第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,该目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。
第三方面,本申请实施例提供了一种电子设备,该电子设备包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如第一方面所述的方法的步骤。
第四方面,本申请实施例提供了一种可读存储介质,所述可读存储介质上存储程
序或指令,所述程序或指令被处理器执行时实现如第一方面所述的方法的步骤。
第五方面,本申请实施例提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如第一方面所述的方法。
第六方面,本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如第一方面所述的方法。
在本申请实施例中,电子设备可以获取在电子设备中运行的第一进程的信息;以根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。由于电子设备可以获取在电子设备中运行的第一进程的信息,因此电子设备可以根据获取的第一进程的信息从兼容的至少两个内容分配器中确定与第一进程相匹配的目标内容分配器,即电子设备可以选择一个适合第一进程使用的内存分配器作为目标内存分配器,以管理该第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
图1是本申请实施例提供的一种内存分配器确定方法的流程示意图;
图2是本申请实施例提供的一种内存分配器确定装置的结构示意图;
图3是本申请实施例提供的一种电子设备的硬件结构示意图之一;
图4是本申请实施例提供的一种电子设备的硬件结构示意图之二。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本申请的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。
下面结合附图,通过具体的实施例及其应用场景对本申请实施例提供的内存分配器确定方法进行详细地说明。
本申请实施例中的内存分配器确定方法可以应用于电子设备使用内存分配器的场景。
目前,电子设备的操作系统(例如安卓(Android)系统)为了更好地管理用户进程的内存申请,可以通过内存分配器来管理用户态的内存申请,内存分配器代理了用户进程通过malloc函数、calloc函数、free函数等申请和释放内存函数,近年来电子设备使用的内存分配器主要是Jemalloc内存分配器或者Scudo内存分配器,也就是说,电子设备的操作系统只能包含一种内存分配器(例如:Jemalloc内存分配器),以负责电子设备的内存分配与管理,因此电子设备上运行的进程也都使用Jemalloc内存分配器进行处理。
然而,一方面,不同的内存分配器的实现机制存在较大差异,在性能以及内存占用上的表现也存在一定差异;另一方面,操作系统上运行的进程众多,众多进程使用内存的方式也不尽相同;所以在电子设备运行的众多进程中,一部分进程可能适合使用Jemalloc内存分配器,另一部分可能更适合使用Scudo内存分配器。因此现有技术在内存分配器的选择上,无法做到兼顾所有进程都能使用更适合自己的分配器。本申请提供一种操作系统支持多内存分配器的方法,旨在为操作系统上运行的大部分进程都能使用更适合进程本身业务逻辑的内存分配器。
在本申请实施例提供的方案中,电子设备可以获取在电子设备中运行的第一进程的信息;以根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。由于电子设备可以获取在电子设备中运行的第一进程的信息,因此电子设备可以根据获取的第一进程的信息从兼容的至少两个内容分配器中确定与第一进程相匹配的目标内容分配器,即电子设备可以选择一个适合第一进程使用的内存分配器作为目标内存分配器,以管理该第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
本申请实施例提供一种内存分配器确定方法,图1示出了本申请实施例提供的一种内存分配器确定方法的流程图,该方法可以应用于电子设备。如图1所示,本申请实施例提供的内存分配器确定方法可以包括下述的步骤201和步骤202。
步骤201、电子设备获取在电子设备中运行的第一进程的信息。
可选地,本申请实施例中,上述第一进程可以为与电子设备中任意一个应用程序对应的进程。
可选地,本申请实施例中,上述第一进程的信息可以为第一进程的标识,第一进程的标识可以理解为与该第一进程对应的应用程序的标识。
步骤202、电子设备根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器。
其中,目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。
本申请实施例中,电子设备可以根据第一进程的信息,从电子设备兼容的至少两个内存分配器中查找与第一进程相匹配的目标内存分配器,以在确定目标内存分配器之后,使用该目标内存分配器管理第一进程的内存。
可以理解的,目标内存分配器是运行第一进程效果最好的内存分配器。
可选地,本申请实施例中,在上述步骤202之前,本申请实施例提供的内存分配器确定方法还包括下述的步骤301。
步骤301、电子设备对原始编译条件进行修改,以得到目标编译条件。
其中,在原始编译条件下,电子设备支持一个内存分配器;在目标编译条件下,电子设备兼容至少两个内存分配器。
可选地,本申请实施例中,上述对原始编译条件的修改为对Makefile脚本文件的修改,Makefile脚本文件用于控制编译内容。
可选地,本申请实施例中,电子设备可以通过标准函数库(Libc)或其他能够保存内存分配器的函数库兼容至少两个内存分配器。
可选地,本申请实施例中,电子设备兼容的内存分配器可以为以下至少两项:Scudo
内存分配器、Jemalloc-4.1.0内存分配器、Jemalloc-5.1.0内存分配器。
可选地,本申请实施例中,上述步骤202具体可以通过下述的步骤202a至步骤202c实现。
步骤202a、电子设备根据第一进程的信息,调用第一接口。
本申请实施例中,上述第一接口由内存分配相关的函数实现。
可选地,本申请实施例中,上述第一接口可以为内存分配接口,或者内存释放接口。
可选地,本申请实施例中,上述内存分配接口可以由:malloc函数、calloc函数或realloc函数实现,也可以由其他负责内存分配的函数实现,具体的可以根据实际使用需求确定,本发明实施例不作限定。
可选地,本申请实施例中,上述内存释放接口可以由free函数实现,也可以由其他负责内存释放的函数实现,具体的可以根据实际使用需求确定,本发明实施例不作限定。
可选地,本申请实施例中,上述第一接口为公共接口,或者可以理解为进程能够直接调用的接口。
步骤202b、电子设备通过第一接口,调用第二接口。
本申请实施例中,上述第二接口由查找内存分配器的函数实现。
可选地,本申请实施例中,上述第二接口为在第一接口和内存分配器接口之间增加的中间层接口,该第二接口为电子设备操作系统对应的接口。
可选地,本申请实施例中,上述第二接口可以由vendor_malloc函数、vendor_calloc函数、vendor_realloc函数或vendor_free函数实现,也可以由其他具有查找内存分配器功能的函数实现,具体的可以根据实际使用需求确定,本发明实施例不作限定。
可选地,本申请实施例中,电子设备通过第一接口,调用第二接口可以理解为:电子设备调用第一接口时,重定向或对接到第二接口,以通过第二接口为第一进程选择内存分配器。
可选地,本申请实施例中,第二接口为与第一接口对应的接口。
可以理解,电子设备调用的第一接口为内存分配接口(例如:由calloc函数实现的接口)时,通过第一接口调用的第二接口为与第一接口对应的接口(例如:由vendor_calloc函数实现的接口);或者,在电子设备调用的第一接口为内存释放接口(例如:由free函数实现的接口)时,通过第一接口调用的第二接口为与第一接口对应的接口(例如:由vendor_free函数实现的接口)。
步骤202c、电子设备通过第二接口,从电子设备兼容的至少两个内存分配器中确定目标内存分配器。
可以理解,在电子设备兼容多个内存分配器的情况下,电子设备可以通过第二接口从多个内存分配器中确定适合第一进程使用的内存分配器,以管理第一进程的内存。
可选地,本申请实施例中,上述第一接口为内存分配接口,目标内存分配器用于为第一进程分配内存。或者,上述第一接口为内存释放接口,目标内存分配器用于释放第一进程的内存。
具体地,上述第一接口为内存分配接口时,电子设备通过第一接口调用与内存分配接口对应的第二接口,然后第二接口确定与第一进程对应的目标内存分配器之后,通过与第一接口对应的负责分配内存的目标内存分配器接口,为第一进程分配内存。
例如:在电子设备调用的第一接口由malloc函数实现的情况下,电子设备通过第一接口调用的第二接口为由vendor_malloc函数实现的接口,然后第二接口确定目标内存分配器为Scudo内存分配器之后,可以通过由Scudo-malloc函数实现的接口为第一进程分配内存。
具体地,上述第一接口为内存释放接口时,电子设备通过第一接口调用与内存释放接口对应的第二接口,然后第二接口确定与第一进程对应的目标内存分配器之后,通过与第一接口对应的负责释放内存的目标内存分配器接口,为第一进程释放内存。
例如:在电子设备调用的第一接口由free函数实现的情况下,电子设备通过第一接口调用的第二接口为由vendor_free函数实现的接口,然后第二接口确定目标内存分配器为Jemalloc内存分配器之后,可以通过由Jemalloc-free函数实现的接口为第一进程释放内存。
本申请实施例提供一种内存分配器确定方法,电子设备可以获取在电子设备中运行的第一进程的信息;以根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。由于电子设备可以获取在电子设备中运行的第一进程的信息,因此电子设备可以根据获取的第一进程的信息从兼容的至少两个内容分配器中确定与第一进程相匹配的目标内容分配器,即电子设备可以选择一个适合第一进程使用的内存分配器作为目标内存分配器,以管理该第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
可选地,本申请实施例中,上述步骤202中的“电子设备从电子设备兼容的至少两个内存分配器中确定目标内存分配器”具体可以通过下述的步骤401和步骤402实现。
步骤401、电子设备获取目标结果表。
本申请实施例中,上述目标结果表用于指示进程与内存分配器的对应关系。
本申请实施例中,目标结果表包括至少一个对应关系,每个对应关系为一个进程与一个内存分配器的对应关系。
步骤402、在目标结果表中存在第一进程的信息的情况下,电子设备将目标结果表中与第一进程的信息对应的内存分配器,确定为目标内存分配器。
可以理解,电子设备可以通过至少两个内存分配器对第一进程进行测试,以确定与第一进程对应的内存分配器,并添加到目标结果表中,从而使得目标结果表中存在第一进程的信息。即目标结果表中保存有各进程与其最适合的内存分配器的对应关系。
需要说明的是,对于电子设备可以通过至少两个内存分配器对第一进程进行测试,以确定与第一进程对应的内存分配器,并添加到目标结果表的具体实现方式,将在下述实施例中进行描述,此处不予赘述。
本申请实施例中,电子设备可以获取目标结果表,并根据第一进程的信息在该目标结果表中查找与第一进程对应的内存分配器,以确定目标内存分配器。
具体地,电子设备可以根据第一进程的信息,通过第二接口在目标结果表中查找第一进程,并将与第一进程对应的内存分配器确定为目标内存分配器。
示例性地,如表1所示,表中包括进程1-进程5的标识,以及与每个进程对应的内存分配器,即包括5个对应关系;电子设备可以根据第一进程(例如:进程3)的信息,通过第二接口在目标结果表中查找进程3,并将与进程3对应的内存分配器(例如:进程3对应内存分配器2)确定为目标内存分配器,以通过该内存分配器2管理进程3的内存。
表1(目标结果表)
如此,由于电子设备在运行第一进程、且调用由内存分配相关的函数实现的第一接口时,可以通过第一接口调用由查找内存分配器的函数实现的第二接口,以通过第二接口在目标结果表中查找与第一进程对应的目标内存分配器,以通过目标内存分配器管理第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
可选地,本申请实施例中,上述步骤202中的“电子设备从电子设备兼容的至少两个内存分配器中确定目标内存分配器”具体可以通过下述的步骤501实现。
步骤501、在根据第一进程的信息,确定第一进程为非初次运行的情况下,电子设备获取第一进程的全局变量的数值,并将与第一进程的全局变量的数值对应的内存分配器,确定为目标内存分配器。
本申请实施例中,一个全局变量的数值对应一个内存分配器。
本申请实施例中,每个进程都对应有一个全局变量(flag)。
可选地,本申请实施例中,电子设备可以根据电子设备兼容的至少两个内存分配器,提前设置每个内存分配器与全局变量的数值的对应关系。
例如:与内存分配器1对应的全局变量的数值为1;与内存分配器2对应的全局变量的数值为2;与内存分配器3对应的全局变量的数值为3。即,当flag值为1的时候,指示的是内存分配器1,当flag值为2的时候,指示的是内存分配器2,当flag值为3的时候,指示的是内存分配器3。
可以理解,电子设备可以根据第一进程的信息,通过第二接口在至少一个全局变量的数值中读取第一进程的全局变量的数值,从而将与第一进程的全局变量的数值对应的内存分配器确定为目标内存分配器。
示例性地,如表2所示,表中包括进程1-进程5的标识,以及与每个进程对应的全局变量的数值,即包括5个对应关系;电子设备可以根据第一进程(例如:进程3)的信息,通过第二接口,查找第一进程(例如:进程3)的全局变量的数值,并将进程3的全局变量的数值(例如:Flag=2)对应的内存分配器(例如:内存分配器2)确定为目标内存分配器,以通过内存分配器2管理进程3的内存。
表2
如此,由于电子设备可以通过第二接口获取第一进程的全局变量的数值,并将与第一进程的全局变量的数值对应的内存分配器,确定为目标内存分配器,以管理第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
可选地,本申请实施例中,在上述步骤401之前,本申请实施例提供的内存分配器确定方法还包括下述的步骤601。
步骤601、电子设备根据目标结果表,更新目标结果表中的每个进程对应的全局变量的数值。
其中,不同的全局变量的数值对应不同的内存分配器,目标结果表用于指示进程与内存分配器的对应关系。
可选地,本申请实施例中,针对目标结果表中的进程(即已确定对应的内存分配器的进程),电子设备可以根据内存分配器与全局变量的数值的对应关系,更新目标结果表中的每个进程对应的全局变量的数值。
可以理解,电子设备初次运行第一进程,且通过目标结果表确定该第一进程对应的目标内存分配器之后,可以根据内存分配器与全局变量的数值的对应关系,更新该第一进程对应的全局变量的数值;使得电子设备再次运行该第一进程时,可以直接获取该第一进程的全局变量的数值,以将该第一进程的全局变量的数值对应的内存分配器,确定为目标内存分配器。
如此,无需电子设备每次通过查找目标结果表,才能确定与第一进程对应的内存分配器,从而减少了电子设备的耗时。
可选地,本申请实施例中,电子设备更新目标结果表中的每个进程对应的全局变量的数值,可以理解为初始化每个进程的全局变量的数值,每个进程的全局变量的数值未初始化时,取值为0。
可选地,本申请实施例中,在上述步骤201之前,本申请实施例提供的内存分配器确定方法还包括下述的步骤701至步骤703。
步骤701、在电子设备中不存在与第一进程相关的测试数据的情况下,电子设备通过至少两个内存分配器,对电子设备中的第一进程进行测试,分别得到第一进程使用每个内存分配器时的分值。
可选地,本申请实施例中,电子设备可以通过至少两个内存分配器,对电子设备中的第一进程进行测试,得到第一进程使用每个内存分配器时的性能分值和内存分值。
具体地,电子设备可以通过进程训练模型对第一进程使用至少两个内存分配器时的进程启动时间、进程关键流程耗时等进行测试,以得到第一进程使用每个内存分配器时的性能分值。
具体地,本申请实施例中,电子设备可以通过进程训练模型对第一进程使用至少两个内存分配器时的进程启动内存占用,进程内存占用峰值,进程常驻后台时内存占用等进行测试,以得到第一进程使用每个内存分配器时的内存分值。
可选地,本申请实施例中,电子设备可以根据第一进程使用每个内存分配器时的性能分值和内存分值、第一进程的进程性能权重和电子设备的系统内存权重,确定第一进程使用每个内存分配器时的分值。
可选地,本申请实施例中,上述第一进程的进程性能权重可以为用户根据进程的重要程度设置的。
可选地,本申请实施例中,上述电子设备的系统内存权重可以是根据电子设备的内存确定的。
例如,对于内存较小(例如内存小于一个阈值)的电子设备,电子设备可以设置一个较高的系统内存权重,从而保证电子设备的内存充足;而对于内存较大(例如内存大于一个阈值)的电子设备,由于分配给进程的内存较为充足,所以电子设备可以设置一个较低的系统内存权重,以提高电子设备的性能。
示例性地,以进程1和电子设备兼容两个内存分配器进行说明,进程1可以通过进程训练模型测试进程1使用内存分配器1时的性能分值和内存分值,然后根据进程1使用内存分配器1时的性能分值和内存分值,以及用户设置的进程1的进程性能权重和电子设备的系统内存权重,确定进程1使用内存分配器1时的分值;并且可以通过进程训练模型测试进程1使用内存分配器2时的性能分值和内存分值,然后根据进程1使用内存分配器2时的性能分值和内存分值,以及用户设置的进程1的进程性能权重和电子设备的系统内存权重,确定进程1使用内存分配器2时的分值;以及可以通过进程训练模型测试进程1使用内存分配器3时的性能分值和内存分值,然后根据进程1使用内存分配器3时的性能分值和内存分值,以及用户设置的进程1的进程性能权重和电子设备的系统内存权重,确定进程1使用内存分配器3时的分值,从而得到进程1使用多个内存分配器时的多个分值。
可选地,本申请实施例中,针对第一进程使用每个内存分配器时的分值,电子设备可以通过以下公式计算得到:
总分(total_score)=进程性能权重(process_perf_weight_coefficient)*性能分值(perf_score)+系统内存权重(sys_mem_weight_coefficient)*内存分值(mem_score)。
例如:进程1使用内存分配器1时的性能分值为6分、内存分值为8分,并且进程1的进程性能权重为1,电子设备的系统内存权重为2,则进程1使用内存分配器1时的分值为:1×6+2×8=22分。
步骤702、电子设备将多个分值中的最大分值对应的内存分配器,确定为与第一进程对应的目标内存分配器。
可以理解,第一进程分别使用多个内存分配器进行测试之后,可以得到多个不同的分值,然后电子设备可以将多个分值中最大的分值对应的内存分配器,确定为与第一进程对应的目标内存分配器。
步骤703、电子设备将第一进程与第一进程对应的目标内存分配器相关联,并添加到目标结果表。
如此,后续电子设备在运行第一进程时,可以根据该目标结果表确定与该第一进程对应的目标内存分配器,并通过该目标内存分配器管理第一进程的内存,从而提高了电子设备使用内存分配器的准确性。
可选地,本申请实施例中,上述目标结果表中包括至少一个进程的标识和至少一个内存分配器的标识,每个内存分配器分别对应一个进程。
可选地,本申请实施例中,电子设备中部分进程(例如:与计算器应用程序对应的进程)为非重点进程,在使用不同分配器时的性能和内存占用差异不大,所以可以不参与测试,使用电子设备的默认分配器管理内存,该默认分配器可以为电子设备兼容的至少两个内存分配器中的任意一个内存分配器。
可选地,本申请实施例中,上述目标结果表可以跟随电子设备的系统版本更新而更新。可以理解,在电子设备的系统更新时,电子设备可以通过至少两个内存分配器,重新对电子设备中的进程进行测试,以根据测试结果更新目标结果表。
可选地,本申请实施例中,本申请实施例提供的内存分配器确定方法还可以包括下述的步骤801至步骤803。
步骤801、电子设备显示目标设置界面。
本申请实施例中,上述目标设置界面中包括至少一个进程的标识和至少一个内存分配器的标识,每个内存分配器分别对应一个进程。
可选地,本申请实施例中,电子设备可以在设置界面或者管家应用程序中提供设置进程内存分配器的功能,用户可以进行输入,触发电子设备显示设置进程内存分配器的界面(即目标设置界面)。
步骤802、电子设备接收用户的第一输入。
本申请实施例中,上述第一输入为用于修改目标进程对应的内存分配器的输入。
可选地,本申请实施例中,上述目标进程可以为已经训练过的进程或未训练过的进程。
可以理解,用户可以通过应用商店应用程序下载一些新的应用程序,这些应用程序对应的进程是未通过进程训练模型训练的,电子设备默认这些进程使用默认内存分配器,从而用户可以触发电子设备对这些进程进行训练,得到与这些进程对应的内存分配器。
需要说明的是,针对电子设备对这些进程进行训练的过程描述可以参见上述实施例中对第一进程进行测试的过程描述,此处不再赘述。
可选地,本申请实施例中,上述目标设置界面可以包括第一控件,该第一控件用于触发电子设备训练目标进程。
可选地,本申请实施例中,上述第一输入可以为用户对上述第一控件的触控输入(例如,点击输入,拖动输入,或滑动输入等)或其他可行性输入,以触发电子设备修改目标进程对应的内存分配器,并更新目标设置界面中与目标进程对应的内存分配器的标识,本申请实施例对此不做限定。
步骤803、电子设备响应于第一输入,修改目标进程对应的内存分配器,并更新目标设置界面中与目标进程对应的内存分配器的标识。
可选地,本申请实施例中,电子设备对目标进程进行训练之后,可以同时更新目标结
果表中与目标进程对应的内存分配器。
如此,提高了电子设备确定目标进程使用的内存分配器的灵活性。
需要说明的是,本申请实施例提供的内存分配器确定方法,执行主体可以为电子设备,或者内存分配器确定装置,或者内存分配器确定装置中的控制模块。本申请实施例中以电子设备执行内存分配器确定方法为例,说明本申请实施例提供的内存分配器确定装置。
图2示出了本申请实施例中涉及的内存分配器确定装置的一种可能的结构示意图。如图2所示,该内存分配器确定装置70可以包括:获取模块71和确定模块72。
其中,获取模块71,用于获取在电子设备中运行的第一进程的信息。确定模块72,用于根据获取模块71获取的第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。
本申请实施例提供一种内存分配器确定装置,由于电子设备可以获取在电子设备中运行的第一进程的信息,因此电子设备可以根据获取的第一进程的信息从兼容的至少两个内容分配器中确定与第一进程相匹配的目标内容分配器,即电子设备可以选择一个适合第一进程使用的内存分配器作为目标内存分配器,以管理该第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
在一种可能的实现方式中,本申请实施例提供的内存分配器确定装置70还包括:处理模块。处理模块,用于根据第一进程的信息,调用第一接口,第一接口由内存分配相关的函数实现;并通过第一接口,调用第二接口,第二接口由查找内存分配器的函数实现。确定模块72,具体用于通过第二接口,从电子设备兼容的至少两个内存分配器中确定目标内存分配器。
在一种可能的实现方式中,获取模块71,还用于获取目标结果表,目标结果表用于指示进程与内存分配器的对应关系。确定模块,具体用于在目标结果表中存在第一进程的信息的情况下,将目标结果表中与第一进程的信息对应的内存分配器,确定为目标内存分配器。
在一种可能的实现方式中,获取模块71,还用于在根据第一进程的信息,确定第一进程为非初次运行的情况下,获取第一进程的全局变量的数值。确定模块,具体用于将与第一进程的全局变量的数值对应的内存分配器,确定为目标内存分配器,一个全局变量的数值对应一个内存分配器。
在一种可能的实现方式中,本申请实施例提供的内存分配器确定装置70还包括:更新模块。更新模块,用于在获取模块71获取第一进程的全局变量的数值之前,根据目标结果表,更新目标结果表中的每个进程对应的全局变量的数值,其中,不同的全局变量的数值对应不同的内存分配器,目标结果表用于指示进程与内存分配器的对应关系。
在一种可能的实现方式中,本申请实施例提供的内存分配器确定装置70还包括:处理模块。处理模块,用于在获取模块71获取在电子设备中运行的第一进程的信息之前,在电子设备中不存在与第一进程相关的测试数据的情况下,通过至少两个内存分配器,对电子设备中的第一进程进行测试,分别得到第一进程使用每个内存分配器时的分值。确定模块72,还用于将多个分值中的最大分值对应的内存分配器,确定为与第一进程对应的目标内存分配器。处理模块,还用于将第一进程与第一进程对应的目标内存分配器相关联,
并添加到目标结果表。
在一种可能的实现方式中,本申请实施例提供的内存分配器确定装置70还包括:处理模块。处理模块,用于在确定模块72根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器之前,对原始编译条件进行修改,以得到目标编译条件;其中,在原始编译条件下,电子设备支持一个内存分配器;在目标编译条件下,电子设备兼容至少两个内存分配器。
在一种可能的实现方式中,第一接口为内存分配接口,目标内存分配器用于为第一进程分配内存;或者,第一接口为内存释放接口,目标内存分配器用于释放第一进程的内存。
本申请实施例中的内存分配器确定装置可以是装置,也可以是电子设备中的部件、集成电路、或芯片。该装置可以是移动电子设备,也可以为非移动电子设备。示例性的,移动电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备、移动上网装置(Mobile Internet Device,MID)、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、机器人、可穿戴设备、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本或者个人数字助理(personal digital assistant,PDA)等,还可以为服务器、网络附属存储器(Network Attached Storage,NAS)、个人计算机(personal computer,PC)、电视机(television,TV)、柜员机或者自助机等,本申请实施例不作具体限定。
本申请实施例中的内存分配器确定装置可以为具有操作系统的装置。该操作系统可以为安卓(Android)操作系统,可以为ios操作系统,还可以为其他可能的操作系统,本申请实施例不作具体限定。
本申请实施例提供的内存分配器确定装置能够实现上述方法实施例实现的各个过程,为避免重复,这里不再赘述。
可选地,如图3所示,本申请实施例还提供一种电子设备900,包括处理器901和存储器902,存储器902上存储有可在所述处理器901上运行的程序或指令,该程序或指令被处理器901执行时实现上述方法实施例的各个步骤,且能达到相同的技术效果,为避免重复,这里不再赘述。
需要说明的是,本申请实施例中的电子设备包括上述所述的移动电子设备和非移动电子设备。
图4为实现本申请实施例的一种电子设备的硬件结构示意图。
该电子设备100包括但不限于:射频单元101、网络模块102、音频输出单元103、输入单元104、传感器105、显示单元106、用户输入单元107、接口单元108、存储器109、以及处理器110等部件。
本领域技术人员可以理解,电子设备100还可以包括给各个部件供电的电源(比如电池),电源可以通过电源管理系统与处理器110逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。图4中示出的电子设备结构并不构成对电子设备的限定,电子设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置,在此不再赘述。
其中,处理器110,用于获取在电子设备中运行的第一进程的信息;并根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,目标内存分配器用于管理第一进程的内存,目标内存分配器与第一进程相匹配。
本申请实施例提供一种电子设备,由于电子设备可以获取在电子设备中运行的第一进程的信息,因此电子设备可以根据获取的第一进程的信息从兼容的至少两个内容分配器中确定与第一进程相匹配的目标内容分配器,即电子设备可以选择一个适合第一进程使用的内存分配器作为目标内存分配器,以管理该第一进程的内存,从而提高了电子设备使用内存分配器的灵活性。
可选地,处理器110,还用于根据第一进程的信息,调用第一接口,第一接口由内存分配相关的函数实现;并通过第一接口,调用第二接口,第二接口由查找内存分配器的函数实现。
处理器110,具体用于通过第二接口,从电子设备兼容的至少两个内存分配器中确定目标内存分配器。
可选地,处理器110,还用于获取目标结果表,目标结果表用于指示进程与内存分配器的对应关系。
处理器110,具体用于在目标结果表中存在第一进程的信息的情况下,将目标结果表中与第一进程的信息对应的内存分配器,确定为目标内存分配器。
可选地,处理器110,还用于在根据第一进程的信息,确定第一进程为非初次运行的情况下,获取第一进程的全局变量的数值。
处理器110,具体用于将与第一进程的全局变量的数值对应的内存分配器,确定为目标内存分配器,一个全局变量的数值对应一个内存分配器。
可选地,处理器110,还用于在获取第一进程的全局变量的数值之前,根据目标结果表,更新目标结果表中的每个进程对应的全局变量的数值,其中,不同的全局变量的数值对应不同的内存分配器,目标结果表用于指示进程与内存分配器的对应关系。
可选地,处理器110,还用于在获取在电子设备中运行的第一进程的信息之前,在电子设备中不存在与第一进程相关的测试数据的情况下,通过至少两个内存分配器,对电子设备中的第一进程进行测试,分别得到第一进程使用每个内存分配器时的分值;并将多个分值中的最大分值对应的内存分配器,确定为与第一进程对应的目标内存分配器;以及将第一进程与第一进程对应的目标内存分配器相关联,并添加到目标结果表。
可选地,处理器110,还用于在根据第一进程的信息,从电子设备兼容的至少两个内存分配器中确定目标内存分配器之前,对原始编译条件进行修改,以得到目标编译条件;其中,在原始编译条件下,电子设备支持一个内存分配器;在目标编译条件下,电子设备兼容至少两个内存分配器。
本申请实施例提供的电子设备能够实现上述方法实施例实现的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
本实施例中各种实现方式具有的有益效果具体可以参见上述方法实施例中相应实现方式所具有的有益效果,为避免重复,此处不再赘述。
应理解的是,本申请实施例中,输入单元104可以包括图形处理器(Graphics Processing Unit,GPU)1041和麦克风1042,图形处理器1041对在视频捕获模式或图像捕获模式中由图像捕获装置(如摄像头)获得的静态图片或视频的图像数据进行处理。显示单元106可包括显示面板1061,可以采用液晶显示器、有机发光二极管等形式来配置显示面板1061。用户输入单元107包括触控面板1071以及其他输入设备1072中的至少一种。触控面板
1071,也称为触摸屏。触控面板1071可包括触摸检测装置和触摸控制器两个部分。其他输入设备1072可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆,在此不再赘述。
存储器109可用于存储软件程序以及各种数据。存储器109可主要包括存储程序或指令的第一存储区和存储数据的第二存储区,其中,第一存储区可存储操作系统、至少一个功能所需的应用程序或指令(比如声音播放功能、图像播放功能等)等。此外,存储器109可以包括易失性存储器或非易失性存储器,或者,存储器109可以包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(Read-Only Memory,ROM)、可编程只读存储器(Programmable ROM,PROM)、可擦除可编程只读存储器(Erasable PROM,EPROM)、电可擦除可编程只读存储器(Electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(Random Access Memory,RAM),静态随机存取存储器(Static RAM,SRAM)、动态随机存取存储器(Dynamic RAM,DRAM)、同步动态随机存取存储器(Synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(Double Data Rate SDRAM,DDRSDRAM)、增强型同步动态随机存取存储器(Enhanced SDRAM,ESDRAM)、同步连接动态随机存取存储器(Synch link DRAM,SLDRAM)和直接内存总线随机存取存储器(Direct Rambus RAM,DRRAM)。本申请实施例中的存储器109包括但不限于这些和任意其它适合类型的存储器。
处理器110可包括一个或多个处理单元;可选的,处理器110集成应用处理器和调制解调处理器,其中,应用处理器主要处理涉及操作系统、用户界面和应用程序等的操作,调制解调处理器主要处理无线通信信号,如基带处理器。可以理解的是,上述调制解调处理器也可以不集成到处理器110中。
本申请实施例还提供一种可读存储介质,所述可读存储介质上存储有程序或指令,该程序或指令被处理器执行时实现上述方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
其中,所述处理器为上述实施例中所述的电子设备中的处理器。所述可读存储介质,包括计算机可读存储介质,如计算机只读存储器ROM、随机存取存储器RAM、磁碟或者光盘等。
本申请实施例另提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现上述方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
应理解,本申请实施例提到的芯片还可以称为系统级芯片、系统芯片、芯片系统或片上系统芯片等。
本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如上述方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除
在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。此外,需要指出的是,本申请实施方式中的方法和装置的范围不限按示出或讨论的顺序来执行功能,还可包括根据所涉及的功能按基本同时的方式或按相反的顺序来执行功能,例如,可以按不同于所描述的次序来执行所描述的方法,并且还可以添加、省去、或组合各种步骤。另外,参照某些示例所描述的特征可在其他示例中被组合。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以计算机软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本申请的保护之内。
Claims (21)
- 一种内存分配器确定方法,所述方法包括:获取在电子设备中运行的第一进程的信息;根据所述第一进程的信息,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,所述目标内存分配器用于管理所述第一进程的内存,所述目标内存分配器与所述第一进程相匹配。
- 根据权利要求1所述的方法,其中,所述根据所述第一进程的信息,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器,包括:根据所述第一进程的信息,调用第一接口,所述第一接口由内存分配相关的函数实现;通过所述第一接口,调用第二接口,所述第二接口由查找内存分配器的函数实现;通过所述第二接口,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器。
- 根据权利要求1或2所述的方法,其中,所述从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器,包括:获取目标结果表,所述目标结果表用于指示进程与内存分配器的对应关系;在所述目标结果表中存在所述第一进程的信息的情况下,将所述目标结果表中与所述第一进程的信息对应的内存分配器,确定为所述目标内存分配器。
- 根据权利要求1或2所述的方法,其中,所述从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器,包括:在根据所述第一进程的信息,确定所述第一进程为非初次运行的情况下,获取所述第一进程的全局变量的数值,并将与所述第一进程的全局变量的数值对应的内存分配器,确定为所述目标内存分配器,一个全局变量的数值对应一个内存分配器。
- 根据权利要求4所述的方法,其中,所述获取所述第一进程的全局变量的数值之前,所述方法还包括:根据目标结果表,更新所述目标结果表中的每个进程对应的全局变量的数值,其中,不同的全局变量的数值对应不同的内存分配器,所述目标结果表用于指示进程与内存分配器的对应关系。
- 根据权利要求1所述的方法,其中,所述获取在电子设备中运行的第一进程的信息之前,所述方法还包括:在所述电子设备中不存在与所述第一进程相关的测试数据的情况下,通过所述至 少两个内存分配器,对所述电子设备中的所述第一进程进行测试,分别得到所述第一进程使用每个内存分配器时的分值;将多个所述分值中的最大分值对应的内存分配器,确定为与所述第一进程对应的目标内存分配器;将所述第一进程与所述第一进程对应的目标内存分配器相关联,并添加到目标结果表。
- 根据权利要求1所述的方法,其中,所述根据所述第一进程的信息,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器之前,所述方法还包括:对原始编译条件进行修改,以得到目标编译条件;其中,在所述原始编译条件下,所述电子设备支持一个内存分配器;在所述目标编译条件下,所述电子设备兼容所述至少两个内存分配器。
- 根据权利要求2所述的方法,其中,所述第一接口为内存分配接口,所述目标内存分配器用于为所述第一进程分配内存;或者,所述第一接口为内存释放接口,所述目标内存分配器用于释放所述第一进程的内存。
- 一种内存分配器确定装置,所述内存分配器确定装置包括:获取模块和确定模块;所述获取模块,用于获取在电子设备中运行的第一进程的信息;所述确定模块,用于根据所述获取模块获取的所述第一进程的信息,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器;其中,所述目标内存分配器用于管理所述第一进程的内存,所述目标内存分配器与所述第一进程相匹配。
- 根据权利要求9所述的装置,其中,所述内存分配器确定装置还包括:处理模块;所述处理模块,用于根据所述第一进程的信息,调用第一接口,所述第一接口由内存分配相关的函数实现;并通过所述第一接口,调用第二接口,所述第二接口由查找内存分配器的函数实现;所述确定模块,具体用于通过所述第二接口,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器。
- 根据权利要求9或10所述的装置,其中,所述获取模块,还用于获取目标结果表,所述目标结果表用于指示进程与内存分配器的对应关系;所述确定模块,具体用于在所述目标结果表中存在所述第一进程的信息的情况下,将所述目标结果表中与所述第一进程的信息对应的内存分配器,确定为所述目标内存分配器。
- 根据权利要求9或10所述的装置,其中,所述获取模块,还用于在根据所述第一进程的信息,确定所述第一进程为非初次运行的情况下,获取所述第一进程的全局变量的数值;所述确定模块,具体用于将与所述第一进程的全局变量的数值对应的内存分配器,确定为所述目标内存分配器,一个全局变量的数值对应一个内存分配器。
- 根据权利要求12所述的装置,其中,所述内存分配器确定装置还包括:更新模块;所述更新模块,用于在所述获取模块获取所述第一进程的全局变量的数值之前,根据目标结果表,更新所述目标结果表中的每个进程对应的全局变量的数值,其中,不同的全局变量的数值对应不同的内存分配器,所述目标结果表用于指示进程与内存分配器的对应关系。
- 根据权利要求9所述的装置,其中,所述内存分配器确定装置还包括:处理模块;所述处理模块,用于在所述获取模块获取在电子设备中运行的第一进程的信息之前,在所述电子设备中不存在与所述第一进程相关的测试数据的情况下,通过所述至少两个内存分配器,对所述电子设备中的所述第一进程进行测试,分别得到所述第一进程使用每个内存分配器时的分值;所述确定模块,还用于将多个所述分值中的最大分值对应的内存分配器,确定为与所述第一进程对应的目标内存分配器;所述处理模块,还用于将所述第一进程与所述第一进程对应的目标内存分配器相关联,并添加到目标结果表。
- 根据权利要求9所述的装置,其中,所述内存分配器确定装置还包括:处理模块;所述处理模块,用于在所述确定模块根据所述第一进程的信息,从所述电子设备兼容的至少两个内存分配器中确定目标内存分配器之前,对原始编译条件进行修改,以得到目标编译条件;其中,在所述原始编译条件下,所述电子设备支持一个内存分配器;在所述目标 编译条件下,所述电子设备兼容所述至少两个内存分配器。
- 根据权利要求10所述的装置,其中,所述第一接口为内存分配接口,所述目标内存分配器用于为所述第一进程分配内存;或者,所述第一接口为内存释放接口,所述目标内存分配器用于释放所述第一进程的内存。
- 一种电子设备,包括处理器,存储器及存储在所述存储器上并可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如权利要求1至8中任一项所述的内存分配器确定方法的步骤。
- 一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如权利要求1至8中任一项所述的内存分配器确定方法的步骤。
- 一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如权利要求1至8中任一项所述的内存分配器确定方法。
- 一种计算机程序产品,所述计算机程序产品被至少一个处理器执行以实现如权利要求1至8中任一项所述的内存分配器确定方法。
- 一种电子设备,用于执行如权利要求1至8中任一项所述的内存分配器确定方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211190505.XA CN115586960A (zh) | 2022-09-28 | 2022-09-28 | 内存分配器确定方法、装置、电子设备及存储介质 |
CN202211190505.X | 2022-09-28 |
Publications (2)
Publication Number | Publication Date |
---|---|
WO2024067348A2 true WO2024067348A2 (zh) | 2024-04-04 |
WO2024067348A3 WO2024067348A3 (zh) | 2024-05-16 |
Family
ID=84772774
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2023/120413 WO2024067348A2 (zh) | 2022-09-28 | 2023-09-21 | 内存分配器确定方法、装置、电子设备及存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN115586960A (zh) |
WO (1) | WO2024067348A2 (zh) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115586960A (zh) * | 2022-09-28 | 2023-01-10 | 维沃移动通信有限公司 | 内存分配器确定方法、装置、电子设备及存储介质 |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP5420972B2 (ja) * | 2009-05-25 | 2014-02-19 | 株式会社東芝 | メモリ管理装置 |
US8225065B2 (en) * | 2010-06-03 | 2012-07-17 | Microsoft Corporation | Hierarchical scalable memory allocator |
CN104102590A (zh) * | 2014-07-22 | 2014-10-15 | 浪潮(北京)电子信息产业有限公司 | 一种异构内存管理方法及装置 |
CN114153615A (zh) * | 2021-12-09 | 2022-03-08 | 腾讯科技(深圳)有限公司 | 内存管理方法、装置、设备、计算机程序及存储介质 |
CN115586960A (zh) * | 2022-09-28 | 2023-01-10 | 维沃移动通信有限公司 | 内存分配器确定方法、装置、电子设备及存储介质 |
-
2022
- 2022-09-28 CN CN202211190505.XA patent/CN115586960A/zh active Pending
-
2023
- 2023-09-21 WO PCT/CN2023/120413 patent/WO2024067348A2/zh unknown
Also Published As
Publication number | Publication date |
---|---|
WO2024067348A3 (zh) | 2024-05-16 |
CN115586960A (zh) | 2023-01-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
TWI529524B (zh) | 應用場景的識別方法、功耗管理方法、裝置及終端設備 | |
US20230112839A1 (en) | Touch control method and apparatus | |
CN109726067B (zh) | 一种进程监控方法以及客户端设备 | |
US20180032259A1 (en) | Method of displaying content and electronic device adapted to the same | |
WO2024067348A2 (zh) | 内存分配器确定方法、装置、电子设备及存储介质 | |
US10198174B2 (en) | Electronic device and method of managing memory of electronic device | |
US10055388B2 (en) | Declarative style rules for default touch behaviors | |
US11455075B2 (en) | Display method when application is exited and terminal | |
CN109213613B (zh) | 图像信息的传输方法、装置、存储介质及电子设备 | |
CN109947671B (zh) | 一种地址转换方法、装置、电子设备及储存介质 | |
US10814229B2 (en) | Fragment-based mobile device application streaming utilizing crowd-sourcing | |
US9990912B2 (en) | Electronic device and method for reproducing sound in the electronic device | |
CN109117153A (zh) | 应用程序的处理方法、装置、终端和存储介质 | |
CN111865630B (zh) | 拓扑信息获取方法、装置、终端及存储介质 | |
CN105760226B (zh) | 一种快速启动移动终端相机的方法、装置及移动终端 | |
CN113157477B (zh) | 内存泄漏的归因方法、装置、电子设备和存储介质 | |
CN111444117B (zh) | 存储空间碎片化实现方法、装置、存储介质及电子设备 | |
CN108089781B (zh) | 界面展示方法和装置 | |
CN110659024B (zh) | 图形资源转换方法、装置、电子设备及存储介质 | |
CN111385661B (zh) | 语音控制全屏播放的方法、装置、终端及存储介质 | |
WO2023284877A1 (zh) | 检测方法、装置及电子设备 | |
WO2022242419A1 (zh) | 分区创建方法、装置、存储介质及计算机设备 | |
CN114070892A (zh) | 数据传输方法和装置 | |
CN112367295A (zh) | 插件展示方法及装置、存储介质及电子设备 | |
CN114513736B (zh) | 一种耳机的声学测试方法、设备、终端及存储介质 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 23870580 Country of ref document: EP Kind code of ref document: A2 |