CN115794413B - Memory processing method and related device - Google Patents

Memory processing method and related device Download PDF

Info

Publication number
CN115794413B
CN115794413B CN202310029668.8A CN202310029668A CN115794413B CN 115794413 B CN115794413 B CN 115794413B CN 202310029668 A CN202310029668 A CN 202310029668A CN 115794413 B CN115794413 B CN 115794413B
Authority
CN
China
Prior art keywords
memory
application
snapshot
terminal equipment
terminal device
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310029668.8A
Other languages
Chinese (zh)
Other versions
CN115794413A (en
Inventor
鲁超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202310029668.8A priority Critical patent/CN115794413B/en
Publication of CN115794413A publication Critical patent/CN115794413A/en
Application granted granted Critical
Publication of CN115794413B publication Critical patent/CN115794413B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)
  • Telephone Function (AREA)

Abstract

The embodiment of the application provides a memory processing method and a related device, and relates to the technical field of terminals. The method comprises the following steps: at a first moment, a first application is switched from a foreground of a terminal device to a background, and the memory size of a snapshot of the first application obtained by the terminal device is a first memory; at a second moment, the second application is switched from the foreground to the background of the terminal equipment, and the memory size of the snapshot of the second application obtained by the terminal equipment is a second memory; at a third moment, switching a third application from a foreground of the terminal equipment to a background, wherein the memory size of a snapshot of the third application obtained by the terminal equipment is a third memory; the first memory is larger than the second memory, the second memory is larger than the third memory, the available memory of the terminal equipment at the first moment is larger than the available memory of the terminal equipment at the second moment, and the available memory of the terminal equipment at the second moment is larger than the available memory of the terminal equipment at the third moment. Therefore, the available memory of the terminal equipment can be saved, and the running fluency of the terminal equipment is improved.

Description

Memory processing method and related device
Technical Field
The present application relates to the field of terminal technologies, and in particular, to a memory processing method and a related device.
Background
With the development of terminal technology, the number of applications in terminal equipment is increased, and the memory occupied by each application is also increased, so that the situation that the available memory space of the terminal equipment is insufficient frequently occurs.
In a possible implementation, the terminal device may close some applications running in the background, thereby saving available memory space. However, when the user wants to use the application, the application needs to be restarted, affecting the user experience.
Disclosure of Invention
The embodiment of the application provides a memory processing method and a related device, which can compress an applied snapshot when the memory of a terminal device is tense, so that the memory of the terminal device is thinned, the available memory of the terminal device is saved, and the running fluency of the terminal device is improved.
In a first aspect, an embodiment of the present application provides a memory processing method, including:
At a first moment, a first application is switched from a foreground of a terminal device to a background, and the memory size of a snapshot of the first application obtained by the terminal device is a first memory; at a second moment, the second application is switched from the foreground to the background of the terminal equipment, and the memory size of the snapshot of the second application obtained by the terminal equipment is a second memory; at a third moment, switching a third application from a foreground of the terminal equipment to a background, wherein the memory size of a snapshot of the third application obtained by the terminal equipment is a third memory; the first memory is larger than the second memory, the second memory is larger than the third memory, the available memory of the terminal equipment at the first moment is larger than the available memory of the terminal equipment at the second moment, and the available memory of the terminal equipment at the second moment is larger than the available memory of the terminal equipment at the third moment. Therefore, memory slimming can be performed for the terminal equipment, and the running smoothness of the terminal equipment is improved.
In one possible implementation, the snapshot of the first application is not compressed, the snapshot of the second application is compressed in a first compression manner, and the snapshot of the third application is compressed in a second compression manner; for the same compression object, the memory occupation of the compression object compressed by the first compression mode is larger than the memory occupation of the compression object compressed by the second compression mode. Therefore, the terminal equipment can determine the compression algorithm according to the size of the self memory, so that the memory space of the terminal equipment is saved, and the user experience is improved.
In one possible implementation, the memory size of the snapshot of the first application, the snapshot of the second application, and the snapshot of the third application before being uncompressed is consistent. Therefore, the terminal equipment can adopt different compression processing modes for snapshots of different applications, so that the memory size occupied by the application snapshots can be flexibly processed according to the memory condition of the terminal equipment, and the memory space is saved for the terminal equipment.
In one possible implementation, the terminal device includes a first screen and a second screen, where the first application, the second application, and the third application are each switched from the foreground to the background in the first screen, or the first application, the second application, and the third application are each switched from the foreground to the background in the second screen. In this way, the snapshot memory sizes of the first application, the second application and the third application can be made to be contrasted.
In one possible implementation, the switching of the first application from the foreground to the background of the terminal device, where the memory size of the snapshot of the first application obtained by the terminal device is the first memory, includes: when a first application is switched from a foreground to a background of a terminal device, the terminal device generates a snapshot of the first application and acquires the size of an available memory of the terminal device; when the available memory of the terminal equipment is larger than a first preset value, the terminal equipment does not compress the snapshot of the first application, and the snapshot of the first application, the memory of which is the first memory, is stored. Therefore, the terminal equipment does not need to compress and decompress the application snapshot, and the calculation force is saved.
In one possible implementation, the second application is switched from the foreground to the background of the terminal device, where the memory size of the snapshot of the second application obtained by the terminal device is the second memory, and the method includes: when the second application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the second application and acquires the size of an available memory of the terminal equipment; when the available memory of the terminal equipment is smaller than or equal to a first preset value and the available memory of the terminal equipment is larger than a second preset value, the terminal equipment compresses the snapshot of the second application in a first compression mode, and the snapshot of the second application with the memory size being the second memory is stored. Therefore, the terminal equipment can rapidly process compression and decompression of the application snapshot, the jamming of the terminal equipment is reduced, and the user experience is improved.
In one possible implementation, the terminal device compresses the snapshot of the second application by adopting a first compression mode, and after storing the snapshot of the second application with the memory size being the second memory, the method further includes: the terminal device destroys the uncompressed snapshot of the second application. In this way, the terminal device can release the memory in the hardware cache by destroying the uncompressed snapshot of the second application, so as to reduce the occupation of the application snapshot to the memory space of the terminal device.
In one possible implementation, the switching of the third application from the foreground to the background of the terminal device, where the memory size of the snapshot of the third application obtained by the terminal device is the third memory, includes: when the third application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the third application and acquires the size of an available memory of the terminal equipment; and when the available memory of the terminal equipment is smaller than or equal to a second preset value, the terminal equipment compresses the snapshot of the third application by adopting a second compression mode, and the snapshot of the third application with the memory size being the third memory is stored. In this way, more memory of the terminal device can be saved.
In one possible implementation, the terminal device compresses the snapshot of the third application by adopting the second compression mode, and after storing the snapshot of the third application with the memory size being the third memory, the method further includes: the terminal device destroys the uncompressed snapshot of the third application. In this way, the terminal device can release the memory in the hardware cache by destroying the uncompressed snapshot of the third application, so as to reduce the occupation of the application snapshot to the memory space of the terminal device.
In a possible implementation, at a fourth moment, the second application is switched from the background to the foreground of the terminal device, and the terminal device decompresses the compressed snapshot; the fourth time is later than the second time; and the terminal equipment displays an interface corresponding to the decompressed snapshot of the second application in the foreground. In this way, the terminal equipment decompresses the compressed snapshot to obtain the original uncompressed snapshot, so that an interface corresponding to the application snapshot can be displayed at the foreground of the terminal equipment, a snapshot function is realized, and user experience is further improved.
In a possible implementation, after the terminal device decompresses the compressed snapshot, the method further includes: the terminal device destroys the compressed snapshot of the second application. In this way, the terminal device can release the memory in the hardware cache by destroying the compressed snapshot of the application, so as to reduce the occupation of the application snapshot to the memory space of the terminal device.
In a second aspect, an embodiment of the present application provides a memory processing apparatus, where the apparatus may be a terminal device, or may be a chip or a chip system in the terminal device. The apparatus may include a processing unit and a display unit. The processing unit is configured to implement any method related to processing performed by the terminal device in the first aspect or any possible implementation manner of the first aspect. The display unit is configured to implement any method related to display performed by the terminal device in the first aspect or any possible implementation manner of the first aspect. When the apparatus is a terminal device, the processing unit may be a processor. The apparatus may further comprise a storage unit, which may be a memory. The storage unit is configured to store instructions, and the processing unit executes the instructions stored in the storage unit, so that the terminal device implements the method described in the first aspect or any one of possible implementation manners of the first aspect. When the apparatus is a chip or a system of chips within a terminal device, the processing unit may be a processor. The processing unit executes the instructions stored by the storage unit to cause the terminal device to implement the method described in the first aspect or any one of the possible implementations of the first aspect. The memory unit may be a memory unit (e.g., a register, a cache, etc.) in the chip, or a memory unit (e.g., a read-only memory, a random access memory, etc.) located outside the chip in the terminal device.
In one possible implementation manner, the processing unit is configured to obtain a memory size of a snapshot of the first application; the memory size is used for obtaining a snapshot of the second application; and is also used to obtain the memory size of the snapshot of the second application.
In a possible implementation manner, the processing unit is configured to compress the snapshot of the second application in a first compression manner; and the method is also used for compressing the snapshot of the third application in a second compression mode.
In one possible implementation, the memory size of the snapshot of the first application, the snapshot of the second application, and the snapshot of the third application before being uncompressed is consistent.
In a possible implementation manner, the terminal device includes a first screen and a second screen, where the first application, the second application and the third application are all switched from the foreground to the background in the first screen, or the first application, the second application and the third application are all switched from the foreground to the background in the second screen.
In a possible implementation manner, a processing unit is configured to generate a snapshot of the first application, and obtain a size of an available memory of the terminal device; and the method is also used for storing the snapshot of the first application with the memory size being the first memory.
In a possible implementation manner, the processing unit is configured to generate a snapshot of the second application, and obtain a size of an available memory of the terminal device; and the method is also used for compressing the snapshot of the second application by adopting a first compression mode and storing the snapshot of the second application with the memory size of the second memory.
In a possible implementation, the processing unit is configured to destroy an uncompressed snapshot of the second application.
In a possible implementation manner, the processing unit is configured to generate a snapshot of the third application, and obtain a size of an available memory of the terminal device; and compressing the snapshot of the third application by adopting a second compression mode, and storing the snapshot of the third application with the memory size of the third memory.
In a possible implementation, the processing unit is configured to destroy an uncompressed snapshot of the third application.
In a possible implementation manner, the processing unit is configured to decompress the compressed snapshot. And the display unit is used for displaying the interface corresponding to the decompressed snapshot of the second application.
In a possible implementation, the processing unit is configured to destroy the compressed snapshot of the second application.
In a third aspect, an embodiment of the present application provides a terminal device, including a processor and a memory, where the memory is configured to store code instructions, and the processor is configured to execute the code instructions to perform the memory processing method described in the first aspect or any one of possible implementation manners of the first aspect.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium having stored therein a computer program or instructions which, when run on a computer, cause the computer to perform the memory processing method described in the first aspect or any one of the possible implementations of the first aspect.
In a fifth aspect, embodiments of the present application provide a computer program product comprising a computer program which, when run on a computer, causes the computer to perform the memory processing method described in the first aspect or any one of the possible implementations of the first aspect.
In a sixth aspect, the present application provides a chip or chip system comprising at least one processor and a communication interface, the communication interface and the at least one processor being interconnected by wires, the at least one processor being adapted to execute a computer program or instructions to perform the memory processing method described in the first aspect or any one of the possible implementations of the first aspect. The communication interface in the chip can be an input/output interface, a pin, a circuit or the like.
In one possible implementation, the chip or chip system described above further includes at least one memory, where the at least one memory has instructions stored therein. The memory may be a memory unit within the chip, such as a register, a cache, etc., or may be a memory unit of the chip (e.g., a read-only memory, a random access memory, etc.).
It should be understood that, the second aspect to the sixth aspect of the present application correspond to the technical solutions of the first aspect of the present application, and the advantages obtained by each aspect and the corresponding possible embodiments are similar, and are not repeated.
Drawings
Fig. 1 is a schematic structural diagram of a terminal device according to an embodiment of the present application;
fig. 2 is a schematic software structure of a terminal device according to an embodiment of the present application;
fig. 3 is a flowchart of generating and acquiring a snapshot by a terminal device according to an embodiment of the present application;
Fig. 4 is a flowchart of a terminal device compressed snapshot and decompressed snapshot according to an embodiment of the present application;
fig. 5 is a flowchart of another terminal device compression snapshot and decompression snapshot provided in an embodiment of the present application;
FIG. 6 is a flowchart of a control strategy for snapshot memory compression according to an embodiment of the present application;
FIG. 7 is a schematic diagram of a memory processing method according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a chip according to an embodiment of the present application.
Detailed Description
In order to facilitate the clear description of the technical solutions of the embodiments of the present application, the following simply describes some terms and techniques involved in the embodiments of the present application:
1. terminology
In embodiments of the present application, the words "first," "second," and the like are used to distinguish between identical or similar items that have substantially the same function and effect. For example, the first chip and the second chip are merely for distinguishing different chips, and the order of the different chips is not limited. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
It should be noted that, in the embodiments of the present application, words such as "exemplary" or "such as" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "for example" should not be construed as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present related concepts in a concrete fashion.
In the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "and/or", describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate: a alone, a and B together, and B alone, wherein a, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b, or c may represent: a, b, c, a-b, a-c, b-c, or a-b-c, wherein a, b, c may be single or plural.
2. Terminal equipment
The terminal device in the embodiment of the application can also be any form of electronic device, for example, the electronic device can include a handheld device, a vehicle-mounted device and the like. For example, some electronic devices are: a mobile phone, a tablet, a palmtop, a notebook, a mobile internet device (mobile INTERNET DEVICE, MID), a wearable device, a Virtual Reality (VR) device, an augmented reality (augmented reality, AR) device, a wireless terminal in industrial control (industrial control), a wireless terminal in unmanned (SELF DRIVING), a wireless terminal in teleoperation (remote medical surgery), a wireless terminal in smart grid (SMART GRID), a wireless terminal in transportation security (transportation safety), a wireless terminal in smart city (SMART CITY), a wireless terminal in smart home (smart home), a cellular phone, a cordless phone, a session initiation protocol (session initiation protocol, SIP) phone, a wireless local loop (wireless local loop, WLL) station, a personal digital assistant (personal DIGITAL ASSISTANT, PDA), a handheld device with wireless communication functionality, a computing device or other processing device connected to a wireless modem, a vehicle-mounted device, a wearable device, a terminal device in a 5G network, or a future evolved land mobile network (public land mobile network), and the like, without limiting the application.
By way of example, and not limitation, in embodiments of the application, the electronic device may also be a wearable device. The wearable device can also be called as a wearable intelligent device, and is a generic name for intelligently designing daily wear by applying wearable technology and developing wearable devices, such as glasses, gloves, watches, clothes, shoes and the like. The wearable device is a portable device that is worn directly on the body or integrated into the clothing or accessories of the user. The wearable device is not only a hardware device, but also can realize a powerful function through software support, data interaction and cloud interaction. The generalized wearable intelligent device includes full functionality, large size, and may not rely on the smart phone to implement complete or partial functionality, such as: smart watches or smart glasses, etc., and focus on only certain types of application functions, and need to be used in combination with other devices, such as smart phones, for example, various smart bracelets, smart jewelry, etc. for physical sign monitoring.
In addition, in the embodiment of the application, the electronic equipment can also be terminal equipment in an internet of things (internet of things, ioT) system, and the IoT is an important component of the development of future information technology, and the main technical characteristics of the IoT are that the article is connected with a network through a communication technology, so that the man-machine interconnection and the intelligent network of the internet of things are realized.
The terminal device in the embodiment of the present application may also be referred to as: a User Equipment (UE), a Mobile Station (MS), a Mobile Terminal (MT), an access terminal, a subscriber unit, a subscriber station, a mobile station, a remote terminal, a mobile device, a user terminal, a wireless communication device, a user agent, or a user equipment, etc.
In the embodiment of the application, the terminal device or each network device comprises a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer. The hardware layer includes hardware such as a central processing unit (central processing unit, CPU), a memory management unit (memory management unit, MMU), and a memory (also referred to as a main memory). The operating system may be any one or more computer operating systems that implement business processes through processes (processes), such as a Linux operating system, a Unix operating system, an Android operating system, an iOS operating system, or a windows operating system. The application layer comprises applications such as a browser, an address book, word processing software, instant messaging software and the like.
By way of example, fig. 1 shows a schematic diagram of a terminal device.
The terminal device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charge management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, keys 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identity module (subscriber identification module, SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyro sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.
It will be appreciated that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the terminal device. In other embodiments of the application, the terminal device may include more or less components than illustrated, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The processor 110 may include one or more processing units, such as: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (IMAGE SIGNAL processor, ISP), a controller, a video codec, a digital signal processor (DIGITAL SIGNAL processor, DSP), a baseband processor, and/or a neural-Network Processor (NPU), etc. Wherein the different processing units may be separate devices or may be integrated in one or more processors.
The controller can generate operation control signals according to the instruction operation codes and the time sequence signals to finish the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system.
In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an integrated circuit (inter-INTEGRATED CIRCUIT, I2C) interface, an integrated circuit built-in audio (inter-INTEGRATED CIRCUIT SOUND, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose input/output (GPIO) interface, a SIM card interface, and/or a USB interface, among others.
It should be understood that the connection relationship between the modules illustrated in the embodiment of the present application is only illustrative, and does not limit the structure of the terminal device. In other embodiments of the present application, the terminal device may also use different interfacing manners in the foregoing embodiments, or a combination of multiple interfacing manners.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to realize expansion of the memory capability of the terminal device. The external memory card communicates with the processor 110 through an external memory interface 120 to implement data storage functions. For example, files such as music, video, etc. are stored in an external memory card.
The internal memory 121 may be used to store computer-executable program code that includes instructions. The internal memory 121 may include a storage program area and a storage data area. The storage program area may store an application program (such as a sound playing function, an image playing function, etc.) required for at least one function of the operating system, etc. The storage data area may store data created during use of the terminal device (such as audio data, phonebook, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (universal flash storage, UFS), and the like. The processor 110 performs various functional applications of the terminal device and data processing by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor. For example, the method of the embodiments of the present application may be performed.
The mobile communication module 150 may provide a solution for wireless communication including 2G/3G/4G/5G or the like applied on a terminal device. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (low noise amplifier, LNA), etc. The mobile communication module 150 may receive electromagnetic waves from the antenna 1, perform processes such as filtering, amplifying, and the like on the received electromagnetic waves, and transmit the processed electromagnetic waves to the modem processor for demodulation.
The wireless communication module 160 may provide solutions for wireless communication including wireless local area network (wireless local area networks, WLAN) (e.g., wireless fidelity (WIRELESS FIDELITY, wi-Fi) network), bluetooth (BT), global navigation satellite system (global navigation SATELLITE SYSTEM, GNSS), frequency modulation (frequency modulation, FM), near field communication (NEAR FIELD communication, NFC), infrared (IR), etc. applied on the terminal device.
The wireless communication module 160 may be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via an antenna, modulates the electromagnetic wave signals, filters the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive a signal to be transmitted from the processor 110, frequency modulate it, amplify it, and convert it to electromagnetic waves for radiation via an antenna.
The terminal device implements display functions through a GPU, a display screen 194, an application processor, and the like. The GPU is a microprocessor for image processing, and is connected to the display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or change display information. The terminal device may implement photographing functions through an ISP, a camera 193, a video codec, a GPU, a display screen 194, an application processor, and the like.
The terminal device may implement audio functions through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, an application processor, and the like. Such as audio playback or recording, etc.
The display screen 194 is used to display images, videos, and the like. The display 194 includes a display panel. In some embodiments, the terminal device may include 1 or N display screens 194, N being a positive integer greater than 1. The terminal device implements display functions through a GPU, a display screen 194, an application processor, and the like. The GPU is a microprocessor for image processing, and is connected to the display 194 and the application processor.
Fig. 2 is a software configuration block diagram of a terminal device according to an embodiment of the present application. The layered architecture divides the software into several layers, each with distinct roles and branches. The layers communicate with each other through a software interface. In some embodiments, the Android system is divided into four layers, from top to bottom, an application layer, an application framework layer, an Zhuoyun rows (Android runtime) and system libraries, a hardware abstraction layer (hardware abstract layer, HAL), and a kernel layer, respectively.
The application layer may include a series of application packages. As shown in fig. 2, the application package may include applications such as telephone, music, camera, etc. Applications may include system applications and three-way applications.
The application framework layer provides an application programming interface (application programming interface, API) and programming framework for the application of the application layer. The application framework layer includes a number of predefined functions.
As shown in FIG. 2, the application framework layer may include a generate/get snapshot, a resource manager, a notification manager, a content provider, a window manager, and the like.
The resource manager provides various resources for the application program, such as localization strings, icons, pictures, layout files, video files, and the like.
The notification manager allows the application to display notification information in a status bar, can be used to communicate notification type messages, can automatically disappear after a short dwell, and does not require user interaction. Such as notification manager is used to inform that the download is complete, message alerts, etc. The notification manager may also be a notification in the form of a chart or scroll bar text that appears on the system top status bar, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in a status bar, giving out a prompt tone, vibrating a terminal device, flashing an indicator light, etc.
The content provider is used for realizing the function of data sharing among different application programs, allowing one program to access the data in the other program, and simultaneously ensuring the safety of the accessed data.
The window manager is used for managing window programs. The window manager may obtain the display screen size, determine if there is a status bar, lock screen, touch screen, drag screen, intercept screen, etc.
Android runtime include core libraries and virtual machines. Android runtime is responsible for scheduling and management of the android system.
The core library consists of two parts: one part is a function which needs to be called by java language, and the other part is a core library of android.
The application layer and the application framework layer run in a virtual machine. The virtual machine executes java files of the application program layer and the application program framework layer as binary files. The virtual machine is used for executing the functions of object life cycle management, stack management, thread management, security and exception management, garbage collection and the like. For example, in the embodiment of the present application, the virtual machine may be used to perform compression and decompression processing on the application snapshot, and destroy the application snapshot in the cache.
The system library may include a plurality of functional modules. For example: media libraries (function libraries), function libraries (function libraries), graphics processing libraries (e.g., openGL ES), etc.
The hardware abstraction layer is a layer of structure that is abstracted between the kernel layer and Android runtime. The hardware abstraction layer may be a package for hardware drivers that provides a unified interface for the invocation of upper layer applications. The hardware abstraction layer may include a data compression module, a management module, a hardware configuration module, and the like.
The data compression module can be used for processing snapshot data, for example, in the embodiment of the application, when the application is switched from the foreground to the background of the terminal equipment, the data compression module can compress the stored snapshot data and clean the original snapshot data before compression; when the application is switched from the background to the foreground of the terminal device, the data compression module can decompress the compressed snapshot data and return the decompressed original snapshot data to the upper-layer application.
The management and control module can monitor the memory use condition of the terminal equipment and can also determine whether the snapshot data of the application need to be compressed or not according to the memory use condition.
The kernel layer is a layer between hardware and software. The kernel layer may include display drivers, camera drivers, audio drivers, and the like.
It should be noted that, the embodiment of the present application is only illustrated by using an android system, and in other operating systems (such as a Windows system, an IOS system, etc.), the scheme of the present application can be implemented as long as the functions implemented by each functional module are similar to those implemented by the embodiment of the present application.
In the terminal device, the user may open a plurality of applications, and may also switch between the plurality of applications. In order to enhance the user experience, when the user opens the latest task on the terminal device, the terminal device may display an interface when each application exits the foreground. And after the terminal device is restarted, when the user opens the latest task, the terminal device can also display an interface when each application exits the foreground before restarting.
In order to achieve the above function, when an application is switched from a foreground to a background of a terminal device, the terminal device may perform a screen capturing operation on an application interface, and generate a screenshot of a current interface of the application, where the screenshot may be referred to as a snapshot (snapshot) of the application, and the snapshot may be understood as a cached application interface in the terminal device. The terminal device may store a snapshot of the application in memory. When the application is switched from the background to the foreground of the terminal device again, the terminal device can load the application by using the snapshot of the application stored in the memory, and display the page corresponding to the snapshot.
By way of example, fig. 3 shows a flow of two parts of the terminal device generating a snapshot and taking the snapshot.
The first part, generating a snapshot.
When an application switches from the foreground to the background, the terminal device may call a function of application exit, e.g., the function of application exit may be handleClosingApps (), which may perform some processing on the application to be switched to the background, where the processing may include creating a snapshot for the application.
In a possible implementation of creating the snapshot, the terminal device may call createTaskSnapshot () function to intercept the photograph of the currently displayed interface for the application. Further, the terminal device may save the snapshot of the application in a cache, e.g., the terminal device may save the snapshot of the application in a mcache cache.
The terminal device may store a snapshot of the application in mcache caches in key-value form. The value may be a snapshot of the application, the key value may be a package name of the application, may be an application identifier (application identification, appId) of the application, may also be other information identifying the application, and specifically, a value of a key value corresponding to the application, which is not limited in the embodiment of the present application.
It will be appreciated that the snapshot in mcache caches may be mapped into hardware cache HardwareBuffer, that is, the snapshot data for the application may be stored in the hardware cache.
And the second part is used for acquiring the snapshot.
When the application is switched from the background to the foreground, the terminal device may call a function of the interface corresponding to the starting application snapshot, for example, the function of the interface corresponding to the starting application snapshot may be addStartWindow (), and the function may display the background application on the foreground of the terminal device. In the process of switching the application to the foreground, the terminal equipment can acquire a snapshot of the application.
In a possible implementation of taking a snapshot, the terminal device may call getSnapshot () function to take a snapshot of the application from the mcache cache. The mcache cache may obtain snapshot data stored in the hardware cache through a mapping relationship with the hardware cache HardwareBuffer.
It will be appreciated that the memory occupied by the snapshot of the application may be related to the screen size of the terminal device, for example, for a folding screen mobile phone, the memory occupied by the snapshot of the application on the external screen of the mobile phone may be about 10MB, and the memory occupied by the snapshot of the application on the internal screen of the mobile phone may be about 17 MB. If the average number of open applications of the user is 14 and the maximum number of open applications is 23, the application snapshot occupies 140MB to 391MB of the memory of the terminal device.
That is, when the number of applications running in the background of the terminal device increases, the snapshot of the applications may occupy more memory space of the terminal device, thereby reducing the available memory space of the terminal device, resulting in a memory shortage of the terminal device.
When the memory of the terminal device is stressed, two effects may occur.
On the one hand, when the application applies for the memory from the terminal device, the terminal device will take a slow path to allocate the memory for the application, that is, the terminal device will execute the memory recovery operation first and then allocate the memory for the application. Compared with the mode that the memory is sufficient and the memory is not required to be allocated for executing the memory recycling action, the efficiency of allocating the memory for the application by adopting a slow path is low, so that the application may be blocked.
On the other hand, the too low memory of the terminal device may trigger the low memory check, that is, when the memory is too low, the terminal device may close a part of the application of the background and recover a part of the memory. Thus, when the user uses the closed application again, the application needs to be restarted, and the terminal equipment cannot quickly display an interface when the application exits the foreground for the user, so that the user experience is affected.
Therefore, according to the memory processing method provided by the embodiment of the application, when the memory of the terminal equipment is tense, the application snapshot can be compressed, so that the memory of the terminal equipment is thinned, the available memory of the terminal equipment is saved, and the running fluency of the terminal equipment is improved.
Fig. 4 shows a processing flow of two parts of compressing a snapshot when a terminal device generates the snapshot and decompressing the snapshot when the snapshot is acquired.
And the first part compresses the snapshot when generating the snapshot.
When the application is switched from the foreground to the background, the process of generating the snapshot by the terminal device and saving the snapshot in the hardware cache HardwareBuffer may refer to the related description in the embodiment corresponding to fig. 3, which is not repeated.
In the embodiment of the present application, the terminal device may compress the snapshot data in the hardware buffer HardwareBuffer, generate compressed hardware buffer data, and store the compressed hardware buffer data in the compressed hardware buffer CompressHardwareBuffer. Meanwhile, the terminal device can destroy the uncompressed original snapshot data stored in the hardware buffer HardwareBuffer.
It can be understood that, based on the embodiment corresponding to fig. 3, the snapshot data in the hardware cache HardwareBuffer is compressed, so that the original execution logic for generating the snapshot in the terminal device can be kept unchanged, and the compatibility of the scheme is ensured, thereby increasing the universality of the terminal device for snapshot processing.
Optionally, when the terminal device generates the snapshot, the terminal device may compress the snapshot data, generate compressed hardware cache data, and store the compressed hardware cache data in the compressed hardware cache CompressHardwareBuffer. At this time, since the uncompressed original snapshot data is not stored in the hardware buffer HardwareBuffer of the terminal device, the terminal device does not need to destroy the snapshot data in the hardware buffer HardwareBuffer, so that the computing power of the terminal device can be saved.
And the second part is used for decompressing the snapshot when the snapshot is acquired.
When the application is switched from the background to the foreground, the process of the terminal device obtaining the snapshot from the cache may refer to the related description in the embodiment corresponding to fig. 3, which is not repeated. It is understood that the terminal device may obtain compressed snapshot data from the compression hardware cache CompressHardwareBuffer.
In the embodiment of the present application, the terminal device may decompress the compressed snapshot data in the compressed hardware buffer CompressHardwareBuffer, generate the original snapshot data of the application, and store the original snapshot data in the hardware buffer HardwareBuffer. Meanwhile, the terminal device may destroy the compressed snapshot data stored in the compressed hardware buffer CompressHardwareBuffer.
By way of example, FIG. 5 illustrates a specific flow of two parts of compressing and decompressing snapshots in accordance with an embodiment of the present application.
As shown in fig. 5, a hardware cache HardwareBuffer may be used to hold uncompressed raw snapshot data, and HardwareBuffer may apply for memory to the terminal device before the raw snapshot data is held at HardwareBuffer. In a possible implementation, hardwareBuffer may call the ioctl and mmap interfaces to apply memory to the DMA area of the terminal device, and the dma_buf memory block applied by HardwareBuffer may be used to store uncompressed raw snapshot data.
The ioctl interface may be used to apply for the memory size to the kernel driver layer of the terminal device. The mmap interface may be used to determine the access mode of the applied memory, e.g., the memory access mode may be readable and/or writable. The DMA area may allocate a multimedia type of memory area for the terminal device, for example, a memory area allocated by the terminal device for pictures, audio, video, etc.
The compression hardware cache CompressHardwareBuffer may be used to store compressed snapshot data, and CompressHardwareBuffer may apply for memory to the terminal device before storing the snapshot data CompressHardwareBuffer. In a possible implementation, compressHardwareBuffer may call the ioctl and mmap interfaces to apply memory to the DMA area of the terminal device, and the dma_buf memory block applied by CompressHardwareBuffer may be used to store the compressed snapshot data.
It can be appreciated that the compressed hardware cache CompressHardwareBuffer may be a module added to implement the compressed snapshot function according to an embodiment of the present application, and CompressHardwareBuffer may compress the original snapshot data in the hardware cache HardwareBuffer.
A first part, a compression flow.
In a possible implementation, after CompressHardwareBuffer applies for the dmabuf memory block, the terminal device may find the hardware buffer HardwareBuffer for storing the original snapshot data according to the file descriptor (fd), and compress the original snapshot data in the buffer. The terminal device may further store the compressed snapshot data in the dma_buf memory block corresponding to CompressHardwareBuffer. Meanwhile, the terminal device can call unmap the interface to release the dma_buf memory block corresponding to the hardware buffer HardwareBuffer, so as to reduce the occupation of the memory space of the terminal device.
And a second part, decompression flow.
In a possible implementation, after HardwareBuffer applies for the dmabuf memory block, the terminal device may find the compressed hardware buffer CompressHardwareBuffer for storing the compressed snapshot data according to fd, and decompress the snapshot data in the buffer. The terminal device may further store the decompressed original snapshot data in the dma_buf memory block corresponding to HardwareBuffer. Meanwhile, the terminal device can call unmap the interface to release the dma_buf memory block corresponding to the compressed hardware buffer CompressHardwareBuffer, so as to reduce the occupation of the memory space of the terminal device.
In the embodiment of the application, the terminal equipment can compress or decompress the snapshot data in different modes. The specific processing manner of compressing or decompressing the snapshot data is not limited in the embodiment of the present application.
In one possible implementation, the terminal device may use a compression algorithm to compress the snapshot data. Illustratively, the compression algorithm may include: memcpy compression algorithm, LZ4 compression algorithm, snappy compression algorithm, zlib compression algorithm, zstd compression algorithm, and the like.
When the compression algorithm is selected, the terminal equipment can consider various factors such as compression efficiency, stability, compression ratio, compression speed, decompression speed and the like. For example, the compression efficiency of the LZ4 compression algorithm is relatively good, and the compression speed and the decompression speed are relatively fast, so that the embodiment of the application can select the LZ4 compression algorithm to compress or decompress the snapshot. It will be appreciated that embodiments of the present application are not limited to the particular compression algorithm employed.
For convenience of description, the compression process performed using the compression algorithm will be referred to as a compression method one in the embodiments of the present application.
It is to be appreciated that the compression method one may be compression of the entire data of the snapshot, and thus, the compression method one may also be referred to as full-scale compression. When the terminal equipment compresses the snapshot in full quantity, the terminal equipment needs to execute a compression calculation process and a decompression calculation process on the snapshot, the execution time is relatively long, but the compression ratio of the first compression mode is relatively high, so that more memory of the terminal equipment can be saved. Therefore, the compression method can be used in a scene with low memory of the terminal equipment.
In another possible implementation, the terminal device may compress the snapshot data by adjusting the snapshot format, that is, the terminal device does not compress the snapshot data, but adjusts the snapshot format with larger memory to the snapshot format with smaller memory. For example, the terminal device may change the format of the snapshot by adjusting the bitmap format bitsPerPixel parameters, for example, the terminal device may adjust the snapshot in RGBA888 format, which occupies a larger memory space, to the snapshot in rgb_565 format, and save the snapshot.
Optionally, the terminal device calculates the memory space occupied by the snapshots corresponding to different formats, and satisfies the following formula:
Wherein, P may be a snapshot currently calculated, numBytes may be a value of memory space occupied by the snapshot, width may be a width of the snapshot, height may be a length of the snapshot, bitsPerPixel may be a bitmap format, and values of bitsPerPixel corresponding to different picture formats may be different.
It can be understood that the display effects of the snapshot in the RGBA888 format and the snapshot in the RGB 565 format are not greatly different, and the calculation according to the above formula shows that, compared with the snapshot in the RGBA888 format, the memory space occupied by the snapshot in the RGB 565 format can be reduced by about 50%, so that the purpose of reducing the memory occupation can be achieved by adjusting the format of the snapshot without affecting the user experience.
For convenience of description, the compression processing performed using the picture format conversion will be referred to as a compression method two in the embodiment of the present application.
It can be understood that the second compression method reduces the memory occupation by modifying the snapshot format, and does not need the calculation process of compressing and decompressing the snapshot, so that the calculation force is smaller, the snapshot processing speed is faster, and the execution time is relatively shorter.
Because the terminal device needs time when performing memory compression, that is, when the terminal device performs memory compression on the snapshot, there is a certain loss in performance, so the terminal device can specify a management and control policy of the memory compression of the snapshot. In a possible implementation, the terminal device may determine the snapshot compression mode to be used according to the remaining available memory in the current terminal device.
Fig. 6 shows a flowchart of a management and control policy for snapshot memory compression according to an embodiment of the present application.
S601, application cutting background.
S602, obtaining available memory information of the terminal equipment.
In a possible implementation, the terminal device may obtain the available memory information of the terminal device by reading the per proc/meminfo information of the terminal device.
After the available memory information of the terminal equipment is obtained, the terminal equipment can determine the memory compression mode of the snapshot according to the size of the available memory.
S603, whether the available memory is higher than a preset value X.
When the available memory is higher than the preset value X, it may be indicated that the available memory of the terminal device is sufficient. When the application is switched from the foreground to the background of the terminal device, the terminal device may not compress the snapshot of the application, and may perform step S604.
When the available memory is lower than or equal to the preset value X, it may be indicated that the available memory of the terminal device is insufficient. When the application is switched from the foreground to the background of the terminal device, the terminal device may perform compression processing on the snapshot of the application, and then step S605 may be performed.
The preset value X may be a larger value of the available memory of the terminal device, for example, the preset value X may be about 2G. It may be understood that the preset value X may be set by the terminal device in a user-defined manner, and the specific value of the preset value X is not limited in the embodiment of the present application.
S604, not compressing.
When the available memory of the terminal device is sufficient, the terminal device may not compress the snapshot of the application, and may store the snapshot into the memory of the terminal device.
S605, whether the available memory is higher than a preset value Y.
When the available memory of the terminal device is insufficient, the terminal device can further determine the compression mode adopted when snapshot compression is applied.
When the available memory is higher than the preset value Y, the available memory of the terminal equipment can be indicated to be smaller, but the application occupying larger memory can be supported to start running. When the application is switched from the foreground to the background of the terminal device, the compression mode II does not need to be processed by a compression algorithm, so that compared with the compression mode I, the compression mode II has smaller calculation power and faster snapshot processing speed. Therefore, the terminal device may perform compression processing on the snapshot of the application in compression mode two, and then may execute step S606.
When the available memory is lower than or equal to the preset value Y, it may be indicated that the available memory of the terminal device is urgent. When the application is switched from the foreground to the background of the terminal equipment, more memory of the terminal equipment can be saved because the compression ratio of the first compression mode is higher. Accordingly, the terminal device can perform compression processing on the snapshot of the application in a compressed manner, and then step S607 can be performed.
The preset value Y may be a larger value of the available memory of the terminal device, for example, the preset value Y may be about 1G. It can be understood that the preset value Y may be set by the terminal device in a user-defined manner, and the specific value of the preset value Y is not limited in the embodiment of the present application.
S606, compressing the second snapshot in a compression mode.
The second compression method may refer to the related description in the embodiment corresponding to fig. 5, and will not be described again.
S607, compressing the pair of snapshots by adopting a compression mode.
The first compression method may refer to the related description in the embodiment corresponding to fig. 5, and will not be described again.
The method according to the embodiment of the present application will be described in detail by way of specific examples. The following embodiments may be combined with each other or implemented independently, and the same or similar concepts or processes may not be described in detail in some embodiments.
Fig. 7 shows a memory processing method according to an embodiment of the application. The method comprises the following steps:
s701, at a first moment, the first application is switched from a foreground to a background of the terminal equipment, and the memory size of the snapshot of the first application obtained by the terminal equipment is a first memory.
In the embodiment of the application, the first time may be a time when the terminal device generates the snapshot for the first application when the first application is switched from the foreground to the background of the terminal device. It can be appreciated that, at the first moment, the available memory of the terminal device is sufficient, and the terminal device may not compress the snapshot of the first application.
The first application may be any application on the terminal device, and the embodiment of the present application is not limited to a specific first application.
The first memory may be a memory size corresponding to a snapshot generated by the terminal device for the first application.
S702, at a second moment, the second application is switched from the foreground to the background of the terminal equipment, and the memory size of the snapshot of the second application obtained by the terminal equipment is the second memory.
In the embodiment of the present application, the second time may be a time when the terminal device generates the snapshot for the second application when the second application is switched from the foreground to the background of the terminal device. It can be understood that, relative to the first moment, the available memory of the terminal device is insufficient at the second moment, but the terminal device can also support the application with larger occupied memory to start and run, and at this time, the terminal device can compress the snapshot of the second application.
The second application may be any application on the terminal device, where the second application and the first application may be the same application or different applications, and the embodiment of the present application is not limited to a specific second application.
The second memory may be a memory size corresponding to a snapshot generated by the terminal device for the second application. The terminal device may compress the snapshot of the second application, so the second memory size may be smaller than the first memory.
And S703, switching the third application from the foreground to the background of the terminal equipment at a third moment, wherein the memory size of the snapshot of the third application obtained by the terminal equipment is a third memory.
In the embodiment of the present application, the third time may be a time when the terminal device generates the snapshot for the third application when the third application is switched from the foreground to the background of the terminal device. It can be appreciated that, at the third moment, the available memory of the terminal device is urgent, and the terminal device can compress the snapshot of the third application.
The third application may be any application on the terminal device, where the third application and the first application or the second application may be the same application or different applications, and the embodiment of the present application is not limited to a specific third application.
The third memory may be a memory size corresponding to a snapshot generated by the terminal device for the third application. The terminal device may compress the snapshot of the third application, so the third memory may be smaller than the first memory.
S704, wherein the first memory is larger than the second memory, the second memory is larger than the third memory, the available memory of the terminal equipment at the first moment is larger than the available memory of the terminal equipment at the second moment, and the available memory of the terminal equipment at the second moment is larger than the available memory of the terminal equipment at the third moment.
In the embodiment of the application, when the memory of the terminal equipment is insufficient, the terminal equipment can compress the applied snapshot, so that the memory of the terminal equipment is reduced, the available memory of the terminal equipment is saved, and the running fluency of the terminal equipment is improved.
Alternatively, on the basis of the embodiment corresponding to fig. 7, it may include: the snapshot of the first application is not compressed, the snapshot of the second application is compressed in a first compression mode, and the snapshot of the third application is compressed in a second compression mode; for the same compression object, the memory occupation of the compression object compressed by the first compression mode is larger than the memory occupation of the compression object compressed by the second compression mode.
In the embodiment of the present application, the first compression mode and the second compression mode may be any compression modes, and it should be noted that the first compression mode and the second compression mode may satisfy: the memory occupation of the compressed object compressed by the first compression mode is larger than the memory occupation of the compressed object compressed by the second compression mode.
The compression object may be an object that needs to be compressed by the first compression method or the second compression method. For example, in an embodiment of the present application, the compressed object may be a snapshot of the application.
For example, the first compression method may be the second compression method for performing the compression processing using the picture format conversion in the embodiment corresponding to fig. 5, and the second compression method may be the first compression method for performing the compression processing using the compression algorithm in the embodiment corresponding to fig. 5. The specific descriptions of the first compression method and the second compression method are not repeated here.
In the embodiment of the application, the terminal equipment can compress the applied snapshot in different compression modes, so that the terminal equipment can determine the compression algorithm according to the size of the self memory, thereby saving the memory space of the terminal equipment, improving the running fluency of the terminal equipment and improving the user experience.
Alternatively, on the basis of the embodiment corresponding to fig. 7, it may include: the memory size of the snapshot of the first application, the snapshot of the second application, and the snapshot of the third application before being uncompressed is consistent.
In the embodiment of the present application, the first application, the second application, and the third application may be the same application or may be different applications. That is, uncompressed snapshot sizes generated by the terminal device may be consistent for different applications. Therefore, the terminal equipment can adopt different compression processing modes for snapshots of different applications, so that the memory size occupied by the application snapshots can be flexibly processed according to the memory condition of the terminal equipment, and the memory space is saved for the terminal equipment.
Alternatively, on the basis of the embodiment corresponding to fig. 7, the terminal device may include a first screen and a second screen, where the first application, the second application, and the third application are all switched from the foreground to the background in the first screen, or the first application, the second application, and the third application are all switched from the foreground to the background in the second screen.
In the embodiment of the application, the sizes of the first screen and the second screen can be the same or different. The folding screen mobile phone may include a mobile phone inner screen and a mobile phone outer screen, where the mobile phone inner screen may be a first screen, the mobile phone outer screen may be a second screen, or the mobile phone outer screen may be a first screen, and the mobile phone inner screen may be a second screen.
Since the memory occupied by the snapshot of the application is related to the screen size of the terminal device, the memory size of the snapshot of the application generated by the terminal device is different for different sizes of screens. The first application, the second application and the third application switch from the foreground to the background in the same screen, so that the snapshot memory sizes of the first application, the second application and the third application have comparability.
Optionally, based on the embodiment corresponding to fig. 7, switching the first application of S701 from the foreground to the background of the terminal device, where the memory size of the snapshot of the first application obtained by the terminal device is the first memory may include: when a first application is switched from a foreground to a background of a terminal device, the terminal device generates a snapshot of the first application and acquires the size of an available memory of the terminal device; when the available memory of the terminal equipment is larger than a first preset value, the terminal equipment does not compress the snapshot of the first application, and the snapshot of the first application, the memory of which is the first memory, is stored.
In the embodiment of the present application, the method for obtaining the available memory size by the terminal device may refer to the description related to S602 in the embodiment corresponding to fig. 6, which is not repeated.
The first preset value may be a value with a larger memory available for the terminal device, and exemplary, the first preset value may be the preset value X in S603 in the embodiment corresponding to fig. 6, and the specific value of the first preset value may refer to the related description of the preset value X and is not repeated.
When the available memory of the terminal equipment is sufficient, the terminal equipment can not compress the application snapshot, so that the terminal equipment can not compress and decompress the application snapshot, and the calculation force is saved.
Optionally, based on the embodiment corresponding to fig. 7, the second application of S702 is switched from the foreground of the terminal device to the background, where the memory size of the snapshot of the second application obtained by the terminal device is a second memory, and the method may include: when the second application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the second application and acquires the size of an available memory of the terminal equipment; when the available memory of the terminal equipment is smaller than or equal to a first preset value and the available memory of the terminal equipment is larger than a second preset value, the terminal equipment compresses the snapshot of the second application in a first compression mode, and the snapshot of the second application with the memory size being the second memory is stored.
In the embodiment of the present application, the second preset value may be a value with smaller available memory of the terminal device, and exemplary, the second preset value may be the preset value Y in S605 of the embodiment corresponding to fig. 6, and the specific value of the second preset value may refer to the related description of the preset value Y and will not be repeated.
When the available memory of the terminal equipment is smaller, but the terminal equipment can also support the application with larger occupied memory to start running, the terminal equipment can compress the snapshot of the application in a first compression mode. Because the computing power of the first compression mode is smaller, the snapshot processing speed is higher, so that the terminal equipment can rapidly process the compression and decompression of the application snapshot, the blocking of the terminal equipment is reduced, and the user experience is improved.
Optionally, on the basis of the embodiment corresponding to fig. 7, after the terminal device compresses the snapshot of the second application by adopting the first compression manner and stores the snapshot of the second application with the memory size being the second memory, the method may further include: the terminal device destroys the uncompressed snapshot of the second application.
In the embodiment of the application, the terminal equipment can release the memory in the hardware cache by destroying the uncompressed snapshot of the second application, so that the occupation of the application snapshot to the memory space of the terminal equipment is reduced.
Optionally, based on the embodiment corresponding to fig. 7, switching the third application in S703 from the foreground to the background of the terminal device, where the memory size of the snapshot of the third application obtained by the terminal device is the third memory, may include: when the third application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the third application and acquires the size of an available memory of the terminal equipment; and when the available memory of the terminal equipment is smaller than or equal to a second preset value, the terminal equipment compresses the snapshot of the third application by adopting a second compression mode, and the snapshot of the third application with the memory size being the third memory is stored.
In the embodiment of the application, when the available memory of the terminal equipment is smaller than or equal to the second preset value, the available memory of the terminal equipment is indicated to be urgent, and the terminal equipment can compress the applied snapshot in a second compression mode. The compression ratio of the second compression mode is higher, so that more memory of the terminal equipment can be saved.
Optionally, on the basis of the embodiment corresponding to fig. 7, after the terminal device compresses the snapshot of the third application by adopting the second compression manner and stores the snapshot of the third application with the memory size being the third memory, the method may further include: the terminal device destroys the uncompressed snapshot of the third application.
In the embodiment of the application, the terminal equipment can release the memory in the hardware cache by destroying the uncompressed snapshot of the third application, so that the occupation of the application snapshot to the memory space of the terminal equipment is reduced.
Optionally, on the basis of the embodiment corresponding to fig. 7, the method further includes: at a fourth moment, the second application is switched from the background to the foreground of the terminal equipment, and the terminal equipment decompresses the compressed snapshot; the fourth time is later than the second time; and the terminal equipment displays an interface corresponding to the decompressed snapshot of the second application in the foreground.
In the embodiment of the present application, the fourth time may be a time when the second application is switched from the background to the foreground of the terminal device, where the terminal device decompresses the compressed snapshot and displays the corresponding interface of the snapshot.
It can be understood that at the fifth moment, the third application is switched from the background to the foreground of the terminal device, and the terminal device can decompress the compressed snapshot; wherein the fifth moment is later than the third moment; the terminal device may further display an interface corresponding to the decompressed snapshot of the third application in the foreground.
The process of decompressing the snapshot by the specific terminal device may refer to the related description of the second portion in the embodiment corresponding to fig. 4 and the related description in the embodiment corresponding to fig. 5, which are not repeated. The process of displaying the interface corresponding to the application snapshot by the foreground of the specific terminal device may refer to the related description of the snapshot obtained in the second portion in the embodiment corresponding to fig. 3, which is not repeated.
The terminal equipment decompresses the compressed snapshot to obtain an original uncompressed snapshot, so that an interface corresponding to the application snapshot can be displayed at the foreground of the terminal equipment, a snapshot function is realized, and user experience is further improved.
Optionally, on the basis of the embodiment corresponding to fig. 7, after the terminal device decompresses the compressed snapshot, the method may further include: the terminal device destroys the compressed snapshot of the second application.
It will be appreciated that after the terminal device decompresses the compressed snapshot of the third application, the terminal device may destroy the compressed snapshot of the third application.
In the embodiment of the application, the terminal equipment can release the memory in the hardware cache by destroying the compressed snapshot of the application, thereby reducing the occupation of the application snapshot to the memory space of the terminal equipment.
It should be noted that, the user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are information and data authorized by the user or fully authorized by each party, and the collection, use and processing of the related data need to comply with the related laws and regulations and standards of the related country and region, and provide corresponding operation entries for the user to select authorization or rejection.
The foregoing description of the solution provided by the embodiments of the present application has been mainly presented in terms of a method. To achieve the above functions, it includes corresponding hardware structures and/or software modules that perform the respective functions. Those of skill in the art will readily appreciate that the present application may be implemented in hardware or a combination of hardware and computer software, as the method steps of the examples described in connection with the embodiments disclosed herein. Whether a function is implemented as hardware or computer software driven hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The embodiment of the application can divide the functional modules of the device for realizing the method according to the method example, for example, each functional module can be divided corresponding to each function, and two or more functions can be integrated in one processing module. The integrated modules may be implemented in hardware or in software functional modules. It should be noted that, in the embodiment of the present application, the division of the modules is schematic, which is merely a logic function division, and other division manners may be implemented in actual implementation.
Fig. 8 is a schematic structural diagram of a chip according to an embodiment of the present application. Chip 800 includes one or more (including two) processors 801, communication lines 802, communication interfaces 803, and memory 804.
In some implementations, the memory 804 stores the following elements: executable modules or data structures, or a subset thereof, or an extended set thereof.
The methods described in the embodiments of the present application may be applied to the processor 801 or implemented by the processor 801. The processor 801 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuitry in hardware in the processor 801 or by instructions in software. The processor 801 may be a general purpose processor (e.g., a microprocessor or a conventional processor), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gates, transistor logic, or discrete hardware components, and the processor 801 may implement or perform the methods, steps, and logic diagrams related to the disclosed processes in the embodiments of the present application.
The steps of the method disclosed in connection with the embodiments of the present application may be embodied directly in the execution of a hardware decoding processor, or in the execution of a combination of hardware and software modules in a decoding processor. The software modules may be located in any well-known storage medium such as ram, rom, or EEPROM (ELECTRICALLY ERASABLE PROGRAMMABLE READ ONLY MEMORY, EEPROM). The storage medium is located in the memory 804, and the processor 801 reads information in the memory 804 and performs the steps of the method described above in combination with its hardware.
The processor 801, the memory 804, and the communication interface 803 may communicate with each other via a communication line 802.
In the above embodiments, the instructions stored by the memory for execution by the processor may be implemented in the form of a computer program product. The computer program product may be written in the memory in advance, or may be downloaded in the form of software and installed in the memory.
Embodiments of the present application also provide a computer program product comprising one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions in accordance with embodiments of the present application are produced in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wired (e.g., coaxial cable, fiber optic, digital subscriber line (digital subscriber line, DSL), or wireless (e.g., infrared, wireless, microwave, etc.), or semiconductor media (e.g., solid state disk (solid state STATE DISK, SSD)), the computer-readable storage medium may be any available medium that can be stored by the computer or a data storage device such as a server, data center, etc., comprising an integration of one or more available media.
The embodiment of the application also provides a computer readable storage medium. The methods described in the above embodiments may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. Computer readable media can include computer storage media and communication media and can include any medium that can transfer a computer program from one place to another. The storage media may be any target media that is accessible by a computer.
As one possible design, the computer-readable medium may include compact disk read-only memory (CD-ROM), RAM, ROM, EEPROM, or other optical disk storage; the computer readable medium may include disk storage or other disk storage devices. Moreover, any connection is properly termed a computer-readable medium. For example, if the software is transmitted from a website, server, or other remote source using a coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. Disk and disc, as used herein, includes Compact Disc (CD), laser disc, optical disc, digital versatile disc (DIGITAL VERSATILE DISC, DVD), floppy disk and blu-ray disc where disks usually reproduce data magnetically, while discs reproduce data optically with lasers.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processing unit of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.

Claims (7)

1. A memory processing method, the method comprising:
at a first moment, a first application is switched from a foreground of a terminal device to a background, and the memory size of a snapshot of the first application obtained by the terminal device is a first memory;
at a second moment, a second application is switched from a foreground of the terminal equipment to a background, and the memory size of a snapshot of the second application obtained by the terminal equipment is a second memory;
At a third moment, a third application is switched from a foreground to a background of the terminal equipment, and the memory size of a snapshot of the third application obtained by the terminal equipment is a third memory;
the first memory is larger than the second memory, the second memory is larger than the third memory, the available memory of the terminal equipment at the first moment is larger than the available memory of the terminal equipment at the second moment, and the available memory of the terminal equipment at the second moment is larger than the available memory of the terminal equipment at the third moment;
the first application is switched from a foreground to a background of the terminal equipment, and the memory size of the snapshot of the first application obtained by the terminal equipment is a first memory, and the method comprises the following steps:
when the first application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the first application and acquires the size of an available memory of the terminal equipment;
When the available memory of the terminal equipment is larger than a first preset value, the terminal equipment does not compress the snapshot of the first application, and the snapshot of the first application, the memory of which is the first memory, is saved;
The second application is switched from the foreground to the background of the terminal equipment, the memory size of the snapshot of the second application obtained by the terminal equipment is a second memory, and the method comprises the following steps:
when the second application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the second application and acquires the size of an available memory of the terminal equipment;
When the available memory of the terminal equipment is smaller than or equal to the first preset value and the available memory of the terminal equipment is larger than a second preset value, the terminal equipment compresses the snapshot of the second application in a first compression mode, and the snapshot of the second application, the memory size of which is the second memory, is stored;
The third application is switched from the foreground to the background of the terminal equipment, the memory size of the snapshot of the third application obtained by the terminal equipment is a third memory, and the method comprises the following steps:
when the third application is switched from the foreground to the background of the terminal equipment, the terminal equipment generates a snapshot of the third application and acquires the size of an available memory of the terminal equipment;
when the available memory of the terminal equipment is smaller than or equal to the second preset value, the terminal equipment compresses the snapshot of the third application in a second compression mode, and the snapshot of the third application, the memory size of which is the third memory, is stored;
for the same compression object, the memory occupation of the compression object compressed by the first compression mode is larger than the memory occupation of the compression object compressed by the second compression mode, the first compression mode is a compression method for performing compression processing by using picture format conversion, and the picture format is converted into a snapshot format for adjusting a snapshot format with large memory to a snapshot format with small memory; the second compression mode is a compression method for performing compression processing by using a compression algorithm, and the compression algorithm is full compression;
The method further comprises the steps of:
The terminal equipment calculates the memory space occupied by the snapshots corresponding to different formats, and the following formula is satisfied: Wherein, P is the snapshot currently calculated, numBytes is the value of the memory space occupied by the snapshot, width is the width of the snapshot, height is the length of the snapshot, bitsPerPixel is the bitmap format, and the values of bitsPerPixel corresponding to different picture formats are different;
The method further comprises the steps of:
The terminal equipment finds a hardware cache for storing the original snapshot according to the file descriptor fd; the terminal equipment compresses the original snapshot and stores the compressed snapshot into a dma_buf memory block corresponding to a compression hardware cache; the compressed hardware cache calls an ioctl interface and a mmap interface to apply DMA (direct memory access) areas of the terminal equipment for dmabuf memory blocks corresponding to the compressed hardware cache; the terminal equipment destroys the original snapshot, and calls unmap interfaces to release dmabuf memory blocks corresponding to the hardware cache; and the hardware cache calls the ioctl interface and the mmap interface to apply the DMA memory block corresponding to the hardware cache to the direct memory access DMA area.
2. The method of claim 1, wherein the snapshot of the first application, the snapshot of the second application, and the snapshot of the third application are consistent in memory size prior to being uncompressed.
3. The method of claim 2, wherein the terminal device comprises a first screen and a second screen, wherein the first application, the second application, and the third application each switch from foreground to background in the first screen, or wherein the first application, the second application, and the third application each switch from foreground to background in the second screen.
4. A method according to any one of claims 1-3, further comprising:
at a fourth moment, the second application is switched from the background to the foreground of the terminal equipment, and the terminal equipment decompresses the compressed snapshot; the fourth time is later than the second time;
and the terminal equipment displays the interface corresponding to the decompressed snapshot of the second application in the foreground.
5. The method of claim 4, wherein after the terminal device decompresses the compressed snapshot, the method further comprises: and the terminal equipment destroys the compressed snapshot of the second application.
6. A terminal device, comprising: a memory for storing a computer program and a processor for executing the computer program to perform the method of any of claims 1-5.
7. A computer readable storage medium storing instructions that, when executed, cause a computer to perform the method of any one of claims 1-5.
CN202310029668.8A 2023-01-09 2023-01-09 Memory processing method and related device Active CN115794413B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310029668.8A CN115794413B (en) 2023-01-09 2023-01-09 Memory processing method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310029668.8A CN115794413B (en) 2023-01-09 2023-01-09 Memory processing method and related device

Publications (2)

Publication Number Publication Date
CN115794413A CN115794413A (en) 2023-03-14
CN115794413B true CN115794413B (en) 2024-05-14

Family

ID=85428822

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310029668.8A Active CN115794413B (en) 2023-01-09 2023-01-09 Memory processing method and related device

Country Status (1)

Country Link
CN (1) CN115794413B (en)

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1901537A (en) * 2005-07-22 2007-01-24 国际商业机器公司 Self adaptive conversation compression managing method and compression managing device and conversation managing system
CN105242987A (en) * 2015-09-22 2016-01-13 浪潮(北京)电子信息产业有限公司 Disaster recovery backup method, apparatus and system for snapshot capacity expansion
CN106803860A (en) * 2017-01-23 2017-06-06 努比亚技术有限公司 The storage processing method and device of a kind of terminal applies
CN106844032A (en) * 2017-01-23 2017-06-13 努比亚技术有限公司 The storage processing method and device of a kind of terminal applies
CN108932163A (en) * 2018-06-15 2018-12-04 奇酷互联网络科技(深圳)有限公司 EMS memory management process, device, readable storage medium storing program for executing and terminal
CN109891390A (en) * 2017-08-11 2019-06-14 华为技术有限公司 A kind of application switching method and device
CN110023906A (en) * 2017-10-13 2019-07-16 华为技术有限公司 A kind of method and device compressed and decompress memory shared by processor
CN110837343A (en) * 2019-09-27 2020-02-25 华为技术有限公司 Snapshot processing method and device and terminal
CN110895492A (en) * 2019-12-11 2020-03-20 Oppo(重庆)智能科技有限公司 Device control method, device, storage medium and electronic device
CN111526151A (en) * 2020-04-28 2020-08-11 网易(杭州)网络有限公司 Data transmission method and device, electronic equipment and storage medium
CN112433848A (en) * 2020-11-10 2021-03-02 北京金山云网络技术有限公司 Resource processing method, device, storage medium and cache server
WO2022052677A1 (en) * 2020-09-09 2022-03-17 华为技术有限公司 Interface display method and electronic device
CN115357389A (en) * 2022-08-22 2022-11-18 维沃移动通信有限公司 Memory management method and device and electronic equipment

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1901537A (en) * 2005-07-22 2007-01-24 国际商业机器公司 Self adaptive conversation compression managing method and compression managing device and conversation managing system
CN105242987A (en) * 2015-09-22 2016-01-13 浪潮(北京)电子信息产业有限公司 Disaster recovery backup method, apparatus and system for snapshot capacity expansion
CN106803860A (en) * 2017-01-23 2017-06-06 努比亚技术有限公司 The storage processing method and device of a kind of terminal applies
CN106844032A (en) * 2017-01-23 2017-06-13 努比亚技术有限公司 The storage processing method and device of a kind of terminal applies
CN109891390A (en) * 2017-08-11 2019-06-14 华为技术有限公司 A kind of application switching method and device
CN110023906A (en) * 2017-10-13 2019-07-16 华为技术有限公司 A kind of method and device compressed and decompress memory shared by processor
CN108932163A (en) * 2018-06-15 2018-12-04 奇酷互联网络科技(深圳)有限公司 EMS memory management process, device, readable storage medium storing program for executing and terminal
CN110837343A (en) * 2019-09-27 2020-02-25 华为技术有限公司 Snapshot processing method and device and terminal
CN110895492A (en) * 2019-12-11 2020-03-20 Oppo(重庆)智能科技有限公司 Device control method, device, storage medium and electronic device
CN111526151A (en) * 2020-04-28 2020-08-11 网易(杭州)网络有限公司 Data transmission method and device, electronic equipment and storage medium
WO2022052677A1 (en) * 2020-09-09 2022-03-17 华为技术有限公司 Interface display method and electronic device
CN112433848A (en) * 2020-11-10 2021-03-02 北京金山云网络技术有限公司 Resource processing method, device, storage medium and cache server
CN115357389A (en) * 2022-08-22 2022-11-18 维沃移动通信有限公司 Memory management method and device and electronic equipment

Also Published As

Publication number Publication date
CN115794413A (en) 2023-03-14

Similar Documents

Publication Publication Date Title
US11947974B2 (en) Application start method and electronic device
CN113254409B (en) File sharing method, system and related equipment
US20230162317A1 (en) Picture Loading Method and Related Apparatus
WO2023202429A1 (en) Garbage recycling method and electronic device
CN115119048B (en) Video stream processing method and electronic equipment
CN111381996B (en) Memory exception handling method and device
CN116700601B (en) Memory optimization method, equipment and storage medium
CN115794413B (en) Memory processing method and related device
CN114077529B (en) Log uploading method and device, electronic equipment and computer readable storage medium
CN113950033B (en) Data transmission method and equipment
CN112783418B (en) Method for storing application program data and mobile terminal
CN114253737A (en) Electronic device, memory recovery method thereof and medium
WO2023169276A1 (en) Screen projection method, terminal device, and computer-readable storage medium
CN113542315B (en) Communication framework, business event processing method and device
CN116048829B (en) Interface calling method, device and storage medium
CN116089320B (en) Garbage recycling method and related device
CN116795476B (en) Wallpaper deleting method and electronic equipment
WO2024032430A1 (en) Memory management method and electronic device
CN117707242A (en) Temperature control method and related device
CN117667506A (en) Drawing library cloning method, system and electronic equipment
CN116069224A (en) Input control method and electronic equipment
CN116737037A (en) Stack management method in interface display and related device
CN116795197A (en) Layer processing method and electronic equipment
CN115981573A (en) Data management method, electronic device and computer readable and writable storage medium
CN116701238A (en) Drive file processing method and related device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant