Memory replacement method and device and electronic equipment
By acquiring the page to be replaced in response to a specified event and determining the target replacement position, the problem of inflexible memory page replacement operation in the prior art is solved, and more flexible and efficient memory management is achieved.
Patent Information
- Application Number
- CN202311092852.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, the replacement operation of memory pages is not flexible enough to dynamically adjust the replacement position according to different events.
A memory permutation method is proposed, which obtains the page to be replaced from memory in response to a specified event and determines the target permutation position based on the event, and realizes dynamic adjustment.
The flexibility of memory page replacement operation is improved, so that different permutation locations can be corresponded to different permutation locations according to different events, and memory utilization and system performance are optimized.
Smart Images

Figure CN119537264A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a memory replacement method, device and electronic device. Background Art
[0002] In memory, data can usually be managed through memory pages. During the operation of an electronic device, the electronic device needs to manage the memory pages in the memory. For example, the electronic device can replace the memory pages in the memory to free up memory space for other processes. However, in the related methods, the replacement operation of the memory page is not flexible enough. Summary of the invention
[0003] In view of the above problems, the present application proposes a memory replacement method, device and electronic device to improve the above problems.
[0004] In a first aspect, the present application provides a memory replacement method, the method comprising: in response to a first specified event trigger, obtaining a memory page to be replaced from a memory; determining a target replacement position based on the first specified event; and replacing the memory page to be replaced to the target replacement position.
[0005] In a second aspect, the present application provides a memory replacement device, which includes: a memory acquisition unit, used to acquire a memory page to be replaced from a memory in response to a first specified event trigger; a replacement position determination unit, used to determine a target replacement position based on the first specified event; and a replacement operation unit, used to replace the memory page to be replaced to the target replacement position.
[0006] In a third aspect, the present application provides an electronic device comprising one or more processors and a memory; one or more programs are stored in the memory and configured to be executed by the one or more processors to implement the above method.
[0007] In a fourth aspect, the present application provides a computer-readable storage medium, in which program code is stored, wherein the above method is executed when the program code is executed by a processor.
[0008] The present application provides a memory replacement method, device, and electronic device. When a first designated event is triggered, the memory page to be replaced can be obtained from the memory in response to the first designated event trigger, and the target replacement position can be determined based on the first designated event to replace the memory page to the target replacement position. Thus, through the above method, when a first designated event that triggers active memory page replacement is triggered, the target replacement position can be determined according to the triggered first designated event, so that different first designated events can correspond to different target replacement positions, thereby improving the flexibility of performing replacement operations on memory pages. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 A flow chart of a memory replacement method proposed in an embodiment of the present application is shown;
[0011] Figure 2 A schematic diagram of a program configuration interface in an embodiment of the present application is shown;
[0012] Figure 3 A flowchart of a memory replacement method proposed in another embodiment of the present application is shown;
[0013] Figure 4 A flowchart of a memory replacement method proposed in another embodiment of the present application is shown;
[0014] Figure 5 A structural block diagram of a memory replacement device proposed in an embodiment of the present application is shown;
[0015] Figure 6 A structural block diagram of an electronic device used to execute a memory replacement method according to an embodiment of the present application is shown in real time of the present application;
[0016] Figure 7 A storage unit in real time of the present application for storing or carrying program codes for implementing the memory replacement method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0017] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0018] Memory, also known as main memory, is a storage space that can be directly addressed by the CPU and is made of semiconductor devices. Processes in electronic devices usually need to use memory to complete data processing during operation. For example, during the startup process, the process will obtain the corresponding memory page for use during the startup process or after startup. In memory, data can usually be managed through memory pages. Among them, during the operation of electronic devices, electronic devices need to manage memory pages in memory. For example, electronic devices can replace memory pages in memory to free up memory space for other processes. However, in related methods, the replacement operation of memory pages is not flexible enough.
[0019] Therefore, the inventors proposed the memory replacement method, device, and electronic device in the present application. When a first designated event is triggered, the memory page to be replaced can be obtained from the memory in response to the first designated event trigger, and the target replacement position can be determined based on the first designated event to replace the memory page to the target replacement position. Thus, through the above method, when a first designated event that triggers active memory page replacement is triggered, the target replacement position can be determined according to the triggered first designated event, so that different first designated events can correspond to different target replacement positions, thereby improving the flexibility of performing replacement operations on memory pages.
[0020] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0021] See also Figure 1 , an embodiment of the present application provides a memory replacement method, the method comprising:
[0022] S110: In response to a first designated event trigger, a memory page to be replaced is obtained from the memory.
[0023] Among them, an event refers to a specific pattern or behavior that occurs at a specific time point or time period and can be detected and identified. In computer science, an event can also refer to an abnormal situation or special condition that occurs during the running of a program, such as a system crash, an abnormal program termination, etc. The triggering and response of an event is one of the mechanisms for the interaction between the operating system and the application of an electronic device. In an embodiment of the present application, the first specified event can be understood as an event that triggers the electronic device to actively perform memory replacement. Among them, memory replacement can be understood as migrating a portion of a memory page (memory data in a memory page) from its original location to other locations (for example, locations outside the memory) according to a certain method to free up more memory space for other programs to use. The main purpose of memory replacement is to optimize memory utilization and improve system performance and response speed.
[0024] As a method, in an embodiment of the present application, the first designated event may include at least one of: a change in the foreground and background running states of the first target application, a change in the screen state of the electronic device, and the startup of the second target application.
[0025] The first target application may be a key application. The key application may include an application that the user is more concerned about, or an application that the user frequently uses. Alternatively, the key application may also include a system-level application. Optionally, the key application may have multiple configuration modes.
[0026] As a method, the user can configure the key application according to his / her needs. In this method, a program configuration interface can be configured in the electronic device, in which candidate applications can be provided, and the user can select the key application from the candidate applications according to his / her needs. For example, Figure 2 As shown, in Figure 2 The program configuration interface 10 shown may include a display area 11 for candidate applications and a display area 12 for key applications. Applications displayed in the display area 11 are applications that may be selected as key applications, and correspondingly, applications displayed in the display area 12 are applications that have been selected as key applications.
[0027] As another way, the electronic device can determine the key application according to the running status of the application. It should be noted that for some applications, when running, they will apply for memory allocation from the electronic device, and the memory required to be allocated for some applications will be large. In this case, optionally, the electronic device can count the memory allocated by the application each time it is started, and then the application whose memory allocated is greater than the first specified memory threshold is used as the key application. Exemplarily, when the program P1 is started, it will apply for memory allocation to the operating system of the electronic device, and the electronic device will respond to the memory allocation request of the program P1 and perform memory allocation, and the electronic device will detect whether the memory allocated by the program P1 is greater than the memory threshold. If it is detected that the memory allocated by the program P1 is greater than the first specified memory threshold, the program P1 will be used as a key application. Among them, before the electronic device uses the application as a key application, it can also first detect whether the application has been determined as a key application, and if the application has not been determined as a key application, it will trigger the configuration of the application as a key application.
[0028] In some cases, some applications will further apply for memory allocation during operation to meet the application's operating needs. For example, for a game program, when it starts running, the memory applied for allocation is the memory required to start the game program. When the game program starts to display the game operation interface, because there will be more content to be displayed in the game operation interface, and because there will be more data to be calculated due to the display of the game operation interface, more memory may be further applied to the electronic device. In this case, the electronic device can record the application that will further apply for memory allocation during operation, and record the application that will further apply for memory allocation during operation as a critical application. Alternatively, the application that will further apply for memory allocation during operation, and the memory further applied for allocation is greater than the second specified memory threshold, is recorded as a critical application.
[0029] Exemplarily, during the running process, program P2 further requests memory allocation from the operating system of the electronic device, and the electronic device allocates memory in response to the memory allocation request of program P2, and the electronic device detects whether the memory further requested for allocation by program P2 is greater than a second specified memory threshold. If it is detected that the memory requested for allocation by program P2 is greater than the second specified memory threshold, program P2 will be treated as a key application.
[0030] In addition, in an embodiment of the present application, the first target application can also be determined according to the memory access delay requirement of the application. In an embodiment of the present application, the memory access delay requirement represents the timeliness requirement of the program when performing memory access. For example, some programs expect that the access request can be responded to quickly when performing memory access, wherein the quick response to the access request can be understood as the data requested to be accessed can be returned to the program quickly, or the quick response to the access request can be understood as the calculation performed in the memory requested can be returned quickly. The calculation result. Optionally, the meaning represented by the memory access delay requirement can be: the maximum delay time that the program can accept. Or, optionally, the meaning represented by the memory access delay requirement can be: the maximum number of memory access delays that the program can accept within a specified time length. In this way, the application whose memory access delay requirement meets the specified requirement conditions can be used as the first target application. Optionally, the specified requirement conditions can be: the maximum delay time is less than the specified time length, or the maximum number of memory access delays is less than the specified number.
[0031] Optionally, the electronic device can group the applications based on the memory access delay requirements of the applications, thereby obtaining multiple program groups. Among them, for the same program group, the memory access delay requirements of the included applications are the same or similar. In this case, an application in one or more of the program groups can be selected as the first target application. For example, a program in a program group with the shortest maximum delay time that the included programs can accept can be selected as the first target application. Alternatively, a program in a program group with the smallest maximum number of memory access delays that the included programs can accept can be selected as the first target application.
[0032] After the memory access latency requirements of the programs to be grouped are obtained, corresponding program groups may be configured for the programs to be grouped.
[0033] As a method, multiple program groups can be preconfigured, and a corresponding memory access latency requirement can be configured for each program group. In this way, after obtaining the application programs to be grouped, the memory access latency requirements of the application programs to be grouped can be compared with the memory access latency requirements corresponding to each program group configuration, so as to group the programs whose corresponding memory access requirements are similar or identical to the memory access requirements of the application programs to be grouped as the groups into which the application programs to be grouped are divided.
[0034] Among them, the two memory access delay requirements are similar, which can be understood as the delay requirements expressed by the two memory access delay requirements are relatively close. For example, taking the meaning represented by the memory access delay requirement as the maximum delay time that the program can accept as an example, the delay requirements expressed by the two memory access delay requirements are relatively close, which can be understood as the difference between the maximum delay times that the two memory access delay requirements can accept is less than the specified threshold. For another example, taking the meaning represented by the memory access delay requirement as the maximum number of memory access delays that the program can accept within a specified time length as an example, the delay requirements expressed by the two memory access delay requirements are relatively close, which can be understood as the difference between the maximum number of memory access delays is less than the specified threshold.
[0035] Exemplarily, the grouping of multiple programs may be shown in the following table:
[0036] ID Group ID Memory access latency requirements for groups 1 Group G1 T1 2 Group G2 T2 3 Group G3 T3
[0037] As shown in the above table, T1, T2 and T3 in the memory access delay requirements of the groups in the above table represent the maximum acceptable delay time. Among them, the values of T1, T2 and T3 can be non-negative numbers. For example, T1 can be 0.5 seconds, T2 can be 1 second, and T3 can be 2 seconds. Based on the situation shown in the above table, after obtaining the application to be grouped, if the maximum acceptable delay time represented by the memory access delay requirement of the application to be grouped is T1, the application to be grouped will be divided into group G1. If the maximum acceptable delay time represented by the memory access delay requirement of the application to be grouped is T3, the application to be grouped will be divided into group G3. If the maximum acceptable delay time represented by the memory access delay requirement of the application to be grouped is T4, and the difference between T4 and T1 is calculated to be less than the specified threshold, it is determined that the memory access delay requirement of the application to be grouped is similar to the memory access delay requirement of group G1, and the application to be grouped will be divided into group G1.
[0038] As a method, if the memory access delay requirement of the program to be grouped is different from and not similar to the memory access delay requirement of each group, it can be detected whether the creation of a new program group is allowed. If it is detected that the creation of a new program group is allowed, a new program group is created, and the memory access requirement of the program to be grouped is used as the memory access requirement of the newly created program group. If the creation of a new program group is not allowed, a group whose corresponding memory access delay requirement is closest to the memory access delay requirement of the program to be grouped is determined from the currently established program groups as the program group corresponding to the program to be grouped.
[0039] Optionally, the electronic device may determine whether to allow the creation of a new program group in a variety of ways.
[0040] As a determination method, the user of the electronic device may configure whether to allow the creation of a new program group. In this method, a configuration interface may be displayed in the electronic device, and the configuration interface may display an option of prohibiting the creation of a new program group and an option of allowing the creation of a new program group. Then, the user may select the desired option according to his or her needs.
[0041] As another determination method, the electronic device can determine whether to allow the creation of a new program group based on the currently remaining storage space. It should be noted that, in the case of creating a new program group, it is necessary to allocate corresponding storage space for the new program group to store corresponding data. The data may include the data of the program group itself to store the data in the program group. Therefore, each time a new program group is created, more storage space is consumed. In this case, the electronic device can determine that a new program group is not allowed to be created if it detects that the remaining storage space is insufficient, and correspondingly, it can determine that a new program group is allowed to be created if it detects that the remaining storage space is sufficient.
[0042] Optionally, when it is detected that the remaining storage space is greater than a specified storage threshold, it is determined that the remaining storage space is sufficient; otherwise, it is determined that the remaining storage space is insufficient.
[0043] It should be noted that, in the embodiment of the present application, the memory access delay requirement of the application can be pre-configured by the developer of the program, or can be determined by the electronic device according to the category and / or running state of the application. Correspondingly, when the memory access delay requirement of the application can be characterized by the memory access delay level, the memory access delay level of the application can be determined according to the category and / or running state of the application.
[0044] For example, if the category of an application indicates that the program is an application running in the foreground or a system program, then the memory access latency requirement of the application indicates that the memory direction requirement of the application needs to be responded to quickly. For another example, if the category of an application indicates that the program is a program running in the background, then the memory access latency requirement of the application indicates that the memory direction requirement of the application can be delayed for a certain period of time before responding.
[0045] It should be noted that the memory access requirements for the same application in different operating states may also be different. For example, for an audio player, in the operating state when it is started and no audio playback is performed, the operations performed may include operations with low timeliness. The operations with low timeliness may include page switching operations, music search operations, or configuration operations. In the operating state of the audio player, when the audio player starts to play audio, the audio player will obtain audio data from the network in real time, and load it into the memory for decoding and playback. Therefore, the audio playback operation performed by the audio player is an operation with high timeliness.
[0046] For another example, for a game program, when it is started and the game operation interface is not entered, the operations performed may include operations with low timeliness. The operations with low timeliness may include page switching operations, game configuration operations, or game item purchase operations, etc. In the game program, when the game operation interface is displayed, the game program will obtain game data (for example, other players' data or real-time map data, etc.) from the network in real time, and load it into the memory for processing. Therefore, when the game program is in the running state of displaying the game operation interface, the memory access request needs to be responded to faster. Among them, when the game program displays the game operation interface, the game operation object in the game operation interface can be controlled.
[0047] In the embodiment of the present application, the programs in the program group may also be deleted. As shown in the foregoing, there may be multiple ways to determine the programs to be grouped, and in this case, there may also be multiple ways to delete the programs in the program group.
[0048] The change in the foreground and background running states of the first target application may be that the first target application switches from the background running state to the foreground running state, or may be that the first target application switches from the non-running state to the foreground running state. When the first target application switches to the foreground running state, it means that the amount of data that the first target application needs to process will increase relatively, thereby requiring more memory.
[0049] In the embodiment of the present application, the second target application may be a large application. Among them, large applications refer to those programs that require a large amount of computing resources and storage resources, can process a large amount of data, and support a large number of users to access at the same time. These applications usually require the use of complex database queries, network traffic, and a large amount of calculations. Therefore, large applications require relatively more memory during startup and operation.
[0050] As a method, the electronic device can determine whether the application is a large application based on the size of the application installation package. It should be noted that for some large applications, the size of their installation packages is usually large. When the electronic device obtains the installation package of the application, it can detect the size of the installation package, and if the size of the installation package of the application is greater than a specified capacity threshold, it determines that the application is a large application.
[0051] As another method, the electronic device can determine whether the application is a large application according to the size of the memory allocated by the application. It should be noted that, as shown in the above content, large applications will have a large amount of data processing requirements during operation, and thus will consume more memory.
[0052] In an embodiment of the present application, the change in the screen state of the electronic device may include the screen state of the electronic device switching from an off screen to a bright screen. Wherein, when the screen switches from an off screen to a bright screen, it means that the electronic device may be used by the user, and then the memory replacement can be performed in advance so that the application that the user expects to use can be run more smoothly. Exemplarily, when the electronic device is in the off screen state, if the user needs to start a game program, it will first trigger the electronic device to switch from the off screen to the bright screen, and then start the game program.
[0053] It should be noted that some of the aforementioned first target applications may be the same as the second target applications.
[0054] As shown in the above content, the first designated event may include multiple contents. As a way, the first designated event may include: the screen state of the electronic device changes, and the foreground and background running states of the first target application change. As a way, the first designated event may include: the screen state of the electronic device changes, and the second target application is started.
[0055] In addition, in the embodiment of the present application, the detection of the trigger of the first specified event can also be understood as the prediction of the trigger of the first specified event. It should be noted that in some cases, whether it is switching the screen of the electronic device from the off screen to the bright screen, or starting a certain application, it can be predicted. For example, if the user is accustomed to getting up at 6 o'clock every morning, then the electronic device can estimate that the electronic device will light up the screen at 6 o'clock every morning by counting the number of times the electronic device is awakened at 6 o'clock every morning. Similarly, the electronic device can also obtain the operating rules of the application by counting the common running time of the application to predict the application that will be started soon. Among them, by predicting the trigger of the first specified event, the memory replacement operation can be performed in advance so that the required memory can be prepared for the application in advance.
[0056] S120: Determine a target replacement position based on the first designated event.
[0057] When a first specified event occurs, the corresponding target replacement position can be determined according to the first specified event. In the embodiment of the present application, the target replacement position can be understood as the position where the memory page to be replaced is replaced. The position can be understood as a storage area in an electronic device. The optional target replacement position can be a memory compression area (ZRAM), flash memory, disk, and network.
[0058] Among them, ZRAM (Zero Capacitor Ram) is a kernel module in an electronic device that can convert the swap space on the hard disk into virtual memory to improve the performance and response speed of the system. ZRAM is the abbreviation of "Compressed Memory Block Device", which implements the function of virtual memory by compressing and decompressing memory blocks. Specifically, ZRAM uses a portion of memory pages (for example, memory pages to be replaced) as a compressed cache. When the system needs more memory, it compresses a portion of memory pages into this cache, thereby releasing more available memory. When these memory blocks are needed, ZRAM will decompress them and return them to the system for use.
[0059] Among them, Flash Memory is a non-volatile memory chip that can be used to store and transfer data between personal computers and digital devices. It has the ability to be electronically reprogrammed and erased. Flash memory is an electronically erasable programmable read-only memory (EEPROM), but it can also be an independent memory storage device, such as a USB drive.
[0060] As a method, in this embodiment, determining the target replacement position based on the first designated event may include: if the first designated event is a change in the foreground and background running states of the first target application, or a change in the screen state of the electronic device, using the memory compression area of the electronic device as the target replacement position. If the first designated event is the startup of the second target application, using the flash memory as the target replacement position.
[0061] It should be noted that when replacing memory pages to different target replacement positions, the time consumed by each replacement process will be different. Among them, the time consumed by replacing memory pages to the memory compression area will be shorter than the time consumed by replacing memory pages to flash memory. However, the size of the memory compression area in the electronic device is usually limited, and it is impossible to replace all memory pages to the memory compression area. Furthermore, for flash memory, the data that can be stored is more than the memory compression area. Then, in order to balance the speed of memory replacement and the size of memory pages that can be replaced, when faster memory allocation is required (for example, the first target application is switched to front and back operation, or the screen of the electronic device is switched from off screen to bright screen), the memory compression area of the electronic device is used as the target replacement position, and the memory page to be replaced is replaced to the boiled memory compression area synchronously. When a large memory space needs to be freed up as soon as possible (for example, the second target application is started), the flash memory of the electronic device is used as the target replacement position, and the memory page to be replaced is replaced to the flash memory synchronously.
[0062] S130: replacing the memory page to be replaced to the target replacement position.
[0063] It should be noted that, in the present application embodiment, replacing the memory page can be understood as replacing the data in the memory page to the target replacement position. In this case, after determining the memory page to be replaced, the data in the memory page to be replaced can be replaced to the target replacement position.
[0064] In the embodiment of the present application, there are multiple ways to determine the memory page to be replaced.
[0065] The memory page to be replaced may be determined according to the usage frequency of the memory page; or, the memory page to be replaced may be determined according to the time when the memory page was added to the memory.
[0066] Optionally, in the method of removing memory pages based on the frequency of use, the time when the memory page was last used can be obtained, and then the memory page to be replaced is determined based on the time when the memory page was last used. Optionally, the interval between the time when the memory page was last used and the current time can be obtained, and if the interval is greater than a specified time, the memory page is determined to be the memory page to be replaced. Optionally, the time when a plurality of memory pages were last used can be compared, and then the memory page with the longest interval between the time and the current time is determined as the memory page to be replaced. The plurality of memory pages can be memory pages of programs in the same program group, and the memory removal policy corresponding to the program group is to remove the memory pages according to the frequency of use of the program in the corresponding program group.
[0067] The memory pages that can be removed may be removed according to the usage frequency of the memory pages of the programs in the corresponding program group, or the LRU (Least Recently Used) method may be used to determine the memory pages that can be removed.
[0068] Exemplarily, the multiple program groups include group G1, group G2, and group G3. Among them, the memory removal strategy corresponding to group G2 is to remove the memory pages according to the usage frequency of the memory pages of the programs in the corresponding program group, then the electronic device will determine the memory pages that can be removed from the memory pages corresponding to the programs in group G2 according to the usage frequency of the memory pages of the programs in the corresponding program group. For example, if the programs included in group G2 are program P5 and program P6, then the electronic device will determine the memory pages that need to be removed according to the usage frequency of the memory pages of program P5 and program P6.
[0069] Optionally, in the method of determining the memory page to be replaced according to the time when the memory page is added to the memory, the memory page to be replaced can be determined by using a FIFO (First Input First Output) method. In this method, the loading time of multiple memory pages loaded into the memory can be compared, and then the memory page with the longest loading time interval from the current time is determined as the memory page to be replaced.
[0070] Exemplarily, the plurality of program groups include group G1, group G2, and group G3. Among them, the memory removal strategy corresponding to group G3 is to determine the memory page to be replaced according to the time when the memory page of the program in the corresponding program group is added to the memory, then the electronic device will determine the memory page to be replaced from the memory page corresponding to the program in group G3 according to the time when the memory page is added to the memory. For example, if the programs included in group G3 are program P7, program P8, and program P9, then the electronic device will determine the memory page to be replaced according to the time when the memory pages of program P7, program P8, and program P9 are loaded into the memory.
[0071] The present embodiment provides a memory replacement method, which can obtain the memory page to be replaced from the memory in response to the triggering of the first specified event when a first specified event is triggered, and can determine the target replacement position based on the first specified event to replace the memory page to the target replacement position. Thus, through the above method, when the first specified event that triggers active memory page replacement is triggered, the target replacement position can be determined according to the triggered first specified event, and different first specified events can correspond to different target replacement positions, thereby improving the flexibility of performing replacement operations on memory pages.
[0072] See also Figure 3 , an embodiment of the present application provides a memory replacement method, the method comprising:
[0073] S210: In response to a first designated event trigger, obtaining a memory page to be replaced from a memory.
[0074] S220: Determine a target replacement position based on the memory requirement characteristics of the first designated event.
[0075] As an approach, the memory requirement characteristics include: a speed requirement for memory allocation and / or a size requirement for memory allocation.
[0076] S230: replacing the memory page to be replaced to the target replacement position.
[0077] The present embodiment provides a memory replacement method, in the case of a first designated event trigger, can respond to the first designated event trigger to obtain the memory page to be replaced from the memory, and can determine the target replacement position based on the first designated event, so as to replace the memory page to be replaced to the target replacement position. In addition, in the present embodiment, the target replacement position can be further determined based on the speed requirement of the first designated event for memory allocation and / or the size requirement for memory allocation, thereby further improving the accuracy of determining the target replacement position.
[0078] See also Figure 4 , an embodiment of the present application provides a memory replacement method, the method comprising:
[0079] S310: In response to the triggering of the first designated event, detecting whether a second designated event occurs.
[0080] It should be noted that, in addition to the triggering of active memory replacement in response to the first specified event provided in the embodiment of the present application, the electronic device can also use memory recycling to free up memory space for other programs to use. For example, the electronic device can trigger memory recycling when the remaining memory is lower than the minimum threshold. Furthermore, the electronic device can trigger memory recycling when a memory allocation failure is detected. Then, in the case where the electronic device itself triggers memory recycling to free up memory space, it is no longer necessary to actively trigger memory replacement to avoid repeated operations and excessive resource overhead.
[0081] In the embodiment of the present application, the second specified event may include the remaining memory being lower than a minimum threshold and / or detecting a memory allocation failure.
[0082] S320: If the second specified event occurs, the memory replacement operation is not performed.
[0083] S330: If the second specified event does not occur, obtain the memory page to be replaced from the memory.
[0084] S340: Determine a target replacement position based on the first designated event.
[0085] S350: replacing the memory page to be replaced to the target replacement position.
[0086] The present embodiment provides a memory replacement method, in the case of a first designated event triggering, the memory page to be replaced can be obtained from the memory in response to the first designated event triggering, and the target replacement position can be determined based on the first designated event, so as to replace the memory page to be replaced to the target replacement position. In addition, in the present embodiment, when the first designated event is triggered, it is also first detected whether a second designated event indicating that no active memory page replacement is required occurs, and then, in the case of no second designated event occurring, active memory page replacement is triggered to avoid excessive resource overhead caused by active memory replacement.
[0087] See also Figure 5 , an embodiment of the present application provides a memory replacement device 400, the device 400 comprising:
[0088] The memory acquisition unit 410 is used to acquire the memory page to be replaced from the memory in response to the triggering of the first specified event.
[0089] As one approach, the first designated event includes: a change in the foreground and background running states of the first target application; or a change in the screen state of the electronic device; or a start-up of the second target application.
[0090] As one approach, an event input by a user is used as the first designated event, and / or an event in which a system freeze occurs when the event is triggered is used as the first designated event.
[0091] The replacement position determining unit 420 is configured to determine a target replacement position based on the first designated event.
[0092] The replacement operation unit 430 is used to replace the memory page to be replaced to the target replacement position.
[0093] As a method, the replacement position determination unit 420 is specifically configured to determine the target replacement position based on the memory requirement characteristics of the first specified event. Optionally, the memory requirement characteristics include: speed requirements for memory allocation and / or size requirements for memory allocation.
[0094] As a method, the replacement position determination unit 420 is specifically used to use the memory compression area of the electronic device as the target replacement position if the first designated event is a change in the foreground and background running states of the first target application, or a change in the screen state of the electronic device; if the first designated event is the startup of the second target application, use the flash memory as the target replacement position.
[0095] As a method, the memory acquisition unit 410 is specifically used to detect whether a second specified event occurs in response to the triggering of the first specified event; if the second specified event does not occur, the memory page to be replaced is obtained from the memory. Optionally, if the second specified event occurs, the memory replacement operation is not performed.
[0096] The present application provides a memory replacement device, which can obtain the memory page to be replaced from the memory in response to the trigger of the first specified event when a first specified event is triggered, and can determine the target replacement position based on the first specified event to replace the memory page to the target replacement position. Thus, through the above-mentioned memory replacement device, when the first specified event that triggers the active replacement of the memory page is triggered, the target replacement position can be determined according to the triggered first specified event, so that different first specified events can correspond to different target replacement positions, thereby improving the flexibility of the replacement operation on the memory page.
[0097] It should be noted that the device embodiment in the present application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment and will not be repeated here.
[0098] The following will be combined Figure 6 An electronic device provided by the present application is described.
[0099] See also Figure 6 Based on the above-mentioned audio processing method and device, the embodiment of the present application also provides another electronic device 200 that can execute the above-mentioned audio processing method. The electronic device 200 includes one or more (only one is shown in the figure) processors 202, a memory 204, a network module 206, a sensor module 208 and an audio acquisition device 210 that are coupled to each other. Among them, the memory 204 stores a program that can execute the content of the above-mentioned embodiment, and the processor 202 can execute the program stored in the memory 204.
[0100] Among them, the processor 202 may include one or more processing cores. The processor 202 uses various interfaces and lines to connect various parts within the entire electronic device 200, and executes various functions and processes data of the electronic device 200 by running or executing instructions, programs, code sets or instruction sets stored in the memory 204, and calling data stored in the memory 204. Optionally, the processor 202 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 202 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 202, but may be implemented separately through a communication chip.
[0101] The memory 204 may include a random access memory (RAM) or a read-only memory (ROM). The memory 204 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 204 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc.
[0102] The network module 206 is used to implement information exchange between the electronic device 200 and other devices, for example, transmission of device control instructions, operation request instructions, and status information acquisition instructions, etc. When the electronic device 200 is specifically a different device, the corresponding network module 206 may be different.
[0103] The sensor module 208 may include at least one sensor. Specifically, the sensor module 208 may include but is not limited to: a light sensor, a motion sensor, a pressure sensor, an infrared heat sensor, a distance sensor, an acceleration sensor, and other sensors.
[0104] Among them, the pressure sensor can be a sensor that detects the pressure generated by pressing on the electronic device 200. That is, the pressure sensor detects the pressure generated by the contact or pressing between the user and the electronic device, such as the pressure generated by the contact or pressing between the user's ear and the mobile terminal. Therefore, the pressure sensor can be used to determine whether contact or pressing occurs between the user and the electronic device 200, and the magnitude of the pressure.
[0105] Among them, the acceleration sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary, and can be used for applications that recognize the posture of the electronic device 200 (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc. In addition, the electronic device 200 can also be equipped with other sensors such as gyroscopes, barometers, hygrometers, thermometers, etc., which will not be repeated here.
[0106] The audio acquisition device 210 is used to collect audio signals. Optionally, the audio acquisition device 210 includes a plurality of audio acquisition devices. The audio acquisition device may be a microphone. For example, in one embodiment, the audio acquisition device 210 may include two microphones, in which one of the microphones may correspond to an analog-to-digital converter, and the other microphone may correspond to an analog-to-digital converter with two different analog gains. In another embodiment, the audio acquisition device 210 may include three microphones. In this embodiment, two of the microphones (e.g., a main microphone and a secondary microphone) may each correspond to an analog-to-digital converter, and the other microphone (e.g., a camera microphone) may correspond to an analog-to-digital converter with two different analog gains.
[0107] As a way, the network module of the electronic device 200 is a radio frequency module, which is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices. The radio frequency module may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM) cards, memories, etc. For example, the radio frequency module can exchange information with an external device through the electromagnetic waves sent or received, and then receive audio signals sent by the external device.
[0108] Furthermore, the electronic device 200 may also include an image acquisition device for image acquisition, for example, a video, a static picture or a dynamic picture may be taken by the image acquisition device.
[0109] Please refer to Figure 7, which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 800 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0110] The computer readable storage medium 800 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer readable storage medium 800 has storage space for program code 810 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 810 can be compressed, for example, in an appropriate form.
[0111] The present application provides a memory replacement method, device, and electronic device. When a first designated event is triggered, the memory page to be replaced can be obtained from the memory in response to the first designated event trigger, and the target replacement position can be determined based on the first designated event to replace the memory page to the target replacement position. Thus, through the above method, when a first designated event that triggers active memory page replacement is triggered, the target replacement position can be determined according to the triggered first designated event, so that different first designated events can correspond to different target replacement positions, thereby improving the flexibility of performing replacement operations on memory pages.
[0112] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A memory replacement method, characterized in that: The method comprises: In response to a first specified event trigger, obtaining a memory page to be replaced from the memory; determining a target replacement position based on the first specified event; The memory page to be replaced is replaced to the target replacement position.
2. The method according to claim 1, characterized in that The determining of the target replacement position based on the first designated event comprises: Based on the memory requirement characteristics of the first designated event, a target replacement position is determined.
3. The method according to claim 2, characterized in that The memory requirement characteristics include: The speed requirement for memory allocation and / or the size requirement for memory allocation.
4. The method according to any one of claims 1 to 3, characterized in that: The first specified event includes: The foreground and background running states of the first target application program change; Or, the screen state of the electronic device changes; Alternatively, a second target application is launched.
5. The method according to claim 4, characterized in that The determining of the target replacement position based on the first designated event comprises: If the first designated event is a change in the foreground and background running states of the first target application, or a change in the screen state of the electronic device, the memory compression area of the electronic device is used as the target replacement position; If the first designated event is the start of the second target application, the flash memory is used as the target replacement location.
6. The method according to claim 1, characterized in that The step of obtaining the memory page to be replaced from the memory in response to the triggering of the first specified event includes: In response to the triggering of the first designated event, detecting whether a second designated event occurs; If the second specified event does not occur, the memory page to be replaced is obtained from the memory.
7. The method according to claim 6, characterized in that The method further comprises: If the second specified event occurs, the memory replacement operation is not performed.
8. The method according to claim 1, characterized in that The method further comprises: The event input by the user is taken as the first designated event, and / or the event in which the system freezes when the event is triggered is taken as the first designated event.
9. A memory replacement device, characterized in that: The device comprises: A memory acquisition unit, configured to acquire a memory page to be replaced from the memory in response to a first specified event trigger; a replacement position determining unit, configured to determine a target replacement position based on the first designated event; The replacement operation unit is used to replace the memory page to be replaced to the target replacement position.
10. An electronic device, characterized in that: The method comprises one or more processors and a memory; one or more programs are stored in the memory and are configured so that the one or more processors execute the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 8 is executed.