Cache management method and related equipment
By creating a background thread on the smart terminal to handle the cache cleaning task, the problem of increased time consumption of the rendering thread is solved, and the application interface is updated in a timely manner and the system fluency is improved.
Patent Information
- Application Number
- CN202211468890.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-22
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2042-11-22
AI Technical Summary
When the smart terminal renders the application interface, the text cache cleaning task is processed in the rendering thread, which causes the rendering thread to take longer and affects the interface update speed and user experience.
By creating a background thread to handle cache cleaning tasks, you avoid performing cache cleaning operations in the rendering thread, thereby reducing the time spent on the rendering thread and updating the application interface in a timely manner.
It effectively improves system fluency, enables electronic devices to update application interfaces in a timely manner, and improves user experience.
Smart Images

Figure CN116662222B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of device management, and in particular to a cache management method and related devices. Background Art
[0002] Smart terminals such as smartphones, personal computers, and smart wearable devices need to render and display the application interface when the application is opened or the foreground application interface is updated. Since the application interface usually includes a large amount of text, the rendering of the text on the application interface will generate a large amount of text cache, which will occupy a large amount of system cache space. In this way, it is easy to frequently trigger the system's cache cleaning mechanism. However, if the cache cleaning task is processed in the rendering thread, it will increase the time consumption of the rendering thread, resulting in the inability to update the application interface in time, causing the system to freeze and affect the user experience. Summary of the invention
[0003] In view of the above, it is necessary to provide a cache management method and related equipment to solve the technical problem that the application interface cannot be updated and displayed in time because the processing of cache cleaning tasks increases the time consumption of the rendering thread.
[0004] In a first aspect, the present application provides a cache management method, the method comprising: in response to a text rendering instruction, obtaining a text data block corresponding to the text to be rendered; determining whether the current text cache satisfies a preset cache cleaning condition; if the current text cache satisfies the preset cache cleaning condition, determining the occupied memory of the text data block to be cleaned; based on the occupied memory of the text data block to be cleaned, obtaining the text data block to be cleaned from the cache space; setting the text data block to be cleaned to a used state; creating a background thread, setting the text data block to be cleaned to an unused state in the background thread, and releasing the memory space occupied by the text data block to be cleaned.
[0005] Through the above technical solution, the time consumption of the rendering thread can be reduced, so that the electronic device can update and display the application interface in a timely manner, effectively improving the system fluency.
[0006] In a possible implementation, setting the text data block to be cleaned up to a use state includes: setting a shared pointer to point to a storage address of the text data block to be cleaned up, so that the shared pointer references the text data block to be cleaned up.
[0007] Through the above technical solution, the text data block to be cleaned can be set to the use state by setting a shared pointer. The setting is simple and convenient, so that the text data block to be cleaned can be cleaned after the background thread is created, which effectively avoids the cache cleaning operation from being executed in the rendering thread, reduces the time consumption of the rendering thread, and allows the electronic device to update and display the application interface in time, effectively improving the system fluency.
[0008] In a possible implementation, the creation of a background thread, setting the text data block to be cleaned to an unused state in the background thread, and releasing the memory space occupied by the text data block to be cleaned includes: creating the background thread, and adding the operations of setting the text data block to be cleaned to an unused state and releasing the memory space occupied by the text data block to be cleaned to the task queue of the background thread; running the background thread, setting the text data block to be cleaned to an unused state, and releasing the memory space occupied by the text data block to be cleaned.
[0009] Through the above technical solution, after the background thread is created, the text data block to be cleaned is set to an unused state, so that the text data block to be cleaned can be cleaned in the background thread, avoiding the cache cleaning operation from being executed in the rendering thread, reducing the time consumption of the rendering thread, and allowing the electronic device to update and display the application interface in a timely manner, effectively improving the system fluency.
[0010] In a possible implementation, the operation of setting the text data block to be cleaned up to an unused state is an operation of resetting the shared pointer.
[0011] Through the above technical solution, the shared pointer can be reset to conveniently set the text data block to be cleaned up to an unused state, so that the cleanup operation of the text data block can be executed in a background thread.
[0012] In a possible implementation, the method further includes: using the descriptor of the data unit corresponding to the acquired text data block as a key and recording the shared pointer pointing to the text data block as a value in a hash table, wherein the data unit corresponds one-to-one to the text data block and is used to record the attributes of the text data block.
[0013] Through the above technical solution, the data unit corresponding to the text data block and the shared pointer pointing to the text data block can be recorded in the hash table in the form of key-value pairs, which is convenient for the system to call the text data block for rendering.
[0014] In a possible implementation, the method further includes: deleting, in the hash table, records associated with the text data block to be cleaned.
[0015] Through the above technical solution, the shared pointer pointing to the text data block to be cleaned can be reset, which is convenient for setting the text data block to be cleaned to an unused state, so that the memory space occupied by the text data block to be cleaned can be released, effectively improving the cache cleaning efficiency.
[0016] In one possible implementation, deleting the record associated with the text data block to be cleaned in the hash table includes: determining the descriptor of the data unit corresponding to the text data block to be cleaned, identifying the key-value pair record with the descriptor as the key in the hash table, and deleting the key-value pair record corresponding to the descriptor.
[0017] Through the above technical solution, the record associated with the text data block to be cleaned can be quickly determined in the hash table, so that the record can be deleted in time, effectively improving the cache cleaning efficiency.
[0018] In one possible implementation, the obtaining of the text data block corresponding to the text to be rendered in response to the text rendering instruction includes: generating a rendering instruction in response to a change in a display interface; determining whether the display interface to be rendered contains text in response to the rendering instruction; if the display interface to be rendered contains text, generating the text rendering instruction, and creating or searching for the text data block corresponding to the text to be rendered in response to the text rendering instruction.
[0019] Through the above technical solution, when the rendering of the display interface is triggered, it can be determined whether the display interface contains text. When it is determined that the display interface contains text, a text data block corresponding to the text to be rendered is created or searched, so that the created or searched text data block meets the scene requirements.
[0020] In one possible implementation, the determining whether the display interface to be rendered contains text in response to the rendering instruction includes: in response to the rendering instruction, obtaining the content of each window in the display interface to be rendered, and identifying whether the content of each window contains text; if the content of any window contains text, determining that the display interface to be rendered contains text; or if the content of all windows does not contain text, determining that the display interface to be rendered does not contain text.
[0021] Through the above technical solution, it is possible to improve the accuracy of judgment by identifying whether each window in the interface to be rendered contains text.
[0022] In one possible implementation, the creating or searching for the text data block corresponding to the text to be rendered includes: obtaining at least one text in the display interface to be rendered, and searching whether the cache space contains the text data block corresponding to the at least one text; if it is found that the cache space contains the text data block corresponding to the at least one text, obtaining the text data block corresponding to the at least one text from the cache space; or if it is not found that the cache space contains the text data block corresponding to any text, creating the text data block corresponding to any text based on the attributes of the any text to be rendered.
[0023] Through the above technical solution, when the cache space contains a text data block of the text to be rendered, the found text data block can be directly returned. When the cache space does not contain a text data block of the text to be rendered, the text data block of the text to be rendered can be created in time to ensure that each text data block of the text to be rendered is obtained, thereby improving the accuracy and efficiency of interface rendering.
[0024] In one possible implementation, the determination of whether the current text cache satisfies a preset cache clearing condition includes: when a text data block corresponding to the text to be rendered is found in the cache space, or when a text data block corresponding to the text to be rendered is created and the created text data block is written into the cache space, determining whether the memory occupied by the text data block in the current cache space is greater than or equal to a memory threshold; if the memory occupied by the text data block in the current cache space is greater than or equal to the memory threshold, determining that the current text cache satisfies the preset cache clearing condition; or if the memory occupied by the text data block in the current cache space is less than the memory threshold, determining that the current text cache does not satisfy the preset cache clearing condition.
[0025] Through the above technical solution, the cache cleaning conditions can be accurately determined so that the cache space can be cleaned up in time when it overflows, ensuring stable and smooth operation of the system.
[0026] In one possible implementation, determining the memory occupied by the text data blocks to be cleaned includes: if the memory occupied by the text data blocks in the current cache space is greater than or equal to the memory threshold, determining the memory difference between the memory occupied by the text data blocks in the current cache space and the memory threshold; judging whether the memory difference is greater than a preset text cache memory space; if the memory difference is greater than the preset text cache memory space, determining that the memory occupied by the text data blocks to be cleaned is at least the memory difference; or if the memory difference is less than or equal to the preset text cache memory space, determining that the memory occupied by the text data blocks to be cleaned is at least the preset text cache memory space.
[0027] Through the above technical solution, it can be ensured that the overflowed cache space can be effectively cleaned up, ensuring stable and smooth operation of the system.
[0028] In a possible implementation, the method of obtaining the text data blocks to be cleaned from the cache space based on the memory occupied by the text data blocks to be cleaned includes: obtaining the text data blocks with the earliest write time and in an unused state from the cache space one by one as the text data blocks to be cleaned, until the memory occupied by all the obtained text data blocks to be cleaned is greater than or equal to the determined memory occupied by the text data blocks to be cleaned.
[0029] Through the above technical solution, the text data blocks that have been written for a long time and are not used can be used as the text data blocks to be cleaned up, so as to avoid the cleaning of the text data blocks affecting the normal operation of the system.
[0030] In a possible implementation, the obtaining of the text data blocks to be cleaned from the cache space based on the memory occupied by the text data blocks to be cleaned includes: obtaining the text data blocks with the longest idle time one by one from the cache space as the text data blocks to be cleaned, until the memory occupied by all the obtained text data blocks to be cleaned is greater than or equal to the memory occupied by the determined text data blocks to be cleaned.
[0031] Through the above technical solution, the text data blocks with less frequent use can be used as the text data blocks to be cleaned up, so as to avoid the cleaning of the text data blocks affecting the normal operation of the system.
[0032] In a possible implementation, the method further includes: in response to a preset operation on the application, releasing the memory space occupied by the text data blocks of the application in the cache space. Through the above technical solution, when the user is not using the application, the cache space occupied by the text data blocks in the application can be released to avoid cache space overflow and ensure stable and smooth operation of the system.
[0033] In a possible implementation, the text data block is used to record the properties of the text to be rendered. Through the above technical solution, the properties of the text to be rendered can be pre-recorded through the text data block, thereby improving the rendering efficiency of the text during the interface rendering process.
[0034] In a second aspect, the present application provides an electronic device, comprising a memory and a processor: wherein the memory is used to store program instructions; the processor is used to read and execute the program instructions stored in the memory, and when the program instructions are executed by the processor, the electronic device executes the above-mentioned cache management method.
[0035] In a third aspect, the present application provides a chip coupled to a memory in an electronic device, wherein the chip is used to control the electronic device to execute the above-mentioned cache management method.
[0036] In a fourth aspect, the present application provides a computer storage medium storing program instructions, which, when executed on an electronic device, enables the electronic device to execute the cache management method described above.
[0037] In addition, the technical effects brought about by the second to fourth aspects can be found in the descriptions related to the methods of each design in the above method part, and will not be repeated here.
[0038] The cache management method and related devices provided in the embodiments of the present application process cache cleaning tasks by creating a background thread, eliminating the need to process cache cleaning tasks in a rendering thread, thereby avoiding increasing the time consumption of a rendering thread. At the same time, after the text cache is cleaned, the system cache space occupancy is reduced, and the rendering thread can render new text in a timely manner, so that the electronic device can update and display the application interface in a timely manner, effectively improving system fluency and thus improving user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1A It is a schematic diagram of a display interface of an electronic device provided in one embodiment of the present application.
[0040] Figure 1B It is a schematic diagram of another display interface of an electronic device provided by an embodiment of the present application.
[0041] Figure 1C It is a schematic diagram of another display interface of an electronic device provided by an embodiment of the present application.
[0042] Figure 2 This is a flowchart of a text cache cleaning process provided by an embodiment of the present application.
[0043] Figure 3 It is a software architecture diagram of an electronic device provided in one embodiment of the present application.
[0044] Figure 4 This is a flowchart of a cache management method provided by an embodiment of the present application.
[0045] Figure 5 It is a flowchart of generating a text data block in response to a text rendering instruction provided by an embodiment of the present application.
[0046] Figure 6 This is a schematic diagram of the status of a text data block in a cache space provided by an embodiment of the present application.
[0047] Figure 7This is a flowchart of creating a background thread and releasing the memory space occupied by the text data block to be cleaned in the background thread, provided by an embodiment of the present application.
[0048] Figure 8 It is a schematic diagram of a background thread provided by an embodiment of the present application.
[0049] Fig. 9 This is a flowchart of a cache management method provided by another embodiment of the present application.
[0050] Fig.10 This is a flowchart of a cache management method provided by another embodiment of the present application.
[0051] Fig.11 This is a flowchart of a cache management method provided by another embodiment of the present application.
[0052] Fig.12 This is a flowchart of releasing the memory space occupied by a text data block provided by an embodiment of the present application.
[0053] Fig.13 This is a hardware architecture diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0054] To facilitate understanding, some illustrations of concepts related to the embodiments of the present application are given by way of example for reference.
[0055] It should be noted that the terms "first" and "second" involved in the embodiments of the present application are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way.
[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by technicians in the technical field in this application. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. It should be understood that, unless otherwise specified in this application, " / " means or. For example, A / B can represent A or B. "And / or" in this application is only a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. "At least one" means one or more. "Multiple" means two or more than two. For example, at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c, a, b and c seven situations.
[0057] The user interface (UI) in the embodiments of the present application is a medium interface for interaction and information exchange between an application or operating system and a user, and can realize the conversion between the internal form of information and the form acceptable to the user. The user interface of an application is a source code written in a specific computer language such as JAVA and Extensible Markup Language (XML). The interface source code is parsed and rendered on an electronic device, and finally presented as content that the user can recognize, such as pictures, text, buttons and other controls. Controls are the basic elements of the user interface. Typical controls include buttons, widgets, toolbars, menu bars, text boxes, scroll bars, images and text. The properties and contents of controls in the interface are defined by tags or nodes, such as XML through <textview> 、 <imgview> 、 <videoview>The controls contained in the interface are specified by nodes such as HTML, CSS, and JavaScript. A node corresponds to a control or attribute in the interface. After parsing and rendering, the node is presented as user-visible content. In addition, many applications, such as hybrid applications, usually also include web pages in their interfaces. A web page, also known as a page, can be understood as a special control embedded in the application interface. A web page is source code written in a specific computer language, such as Hyper Text Markup Language (HTML), Cascading Style Sheets (CSS), JAVA scripts (JavaScript, JS), etc. The web page source code can be loaded and displayed as user-recognizable content by a browser or a web page display component with similar functions to a browser. The specific content contained in a web page is also defined by tags or nodes in the web page source code. For example, HTML is defined by 、 、 <video> 、 <canvas>To define the elements and attributes of a web page.
[0058] The most common form of user interface is graphical user interface (GUI), which refers to a user interface related to computer operation that is displayed in a graphical manner. It can be an icon, window, control or other interface element displayed on the display screen of an electronic device.
[0059] In the absence of conflict, the following embodiments and features of the embodiments may be combined with each other.
[0060] Smart terminals such as smartphones, personal computers, and smart wearable devices need to render and display the application interface when the application is opened or the foreground application interface is updated. Since the application interface usually includes a large amount of text, the rendering of the text on the application interface will generate a large amount of text cache, which will occupy a large amount of system cache space. In this way, it is easy to frequently trigger the system's cache cleaning mechanism. However, if the cache cleaning task is processed in the rendering thread, it will increase the time consumption of the rendering thread, resulting in the inability to update the application interface in time, causing the system to freeze and affect the user experience.
[0061] In order to avoid the situation where the processing of cache cleaning tasks will increase the time consumption of the rendering thread, thereby causing the application interface to be unable to update and display in a timely manner, an embodiment of the present application provides a cache management method, which processes cache cleaning tasks by creating a background thread, so that the cache cleaning tasks do not need to be processed in the rendering thread. The rendering thread can render new text in a timely manner, so that the electronic device can update and display the application interface in a timely manner.
[0062] In order to better understand the cache management method provided in the embodiment of the present application, Figure 1A , Figure 1B , Figure 1C The application scenario of the cache management method of the embodiment of the present application is described.
[0063] See also Figure 1A As shown, the desktop of an electronic device usually displays icons of multiple applications, and the user can perform touch operations on the icons to cold start or hot start the application. Among them, a cold start refers to the start of an application when the application is not in the foreground and there is no application process in the background. A hot start refers to the start of an application when the application is not in the foreground, but there is an application process in the background. In order to optimize the user's visual experience, during the process of starting the application, a dynamic zoom effect can be added to the application icon and the text under the icon (i.e., the application name). When generating a dynamic zoom effect, the application icon and text need to be rendered.
[0064] See also Figure 1B As shown, when the user touches the application icon, that is, when the user's finger touches the display screen area corresponding to the application icon and has not left, the dynamic effect of the application icon is that the brightness of the icon becomes darker than the brightness of other areas of the display screen, and the dynamic effect of the text of the application is that the size of the text (such as font size) becomes smaller than the initial size. At this time, when rendering the current interface, the operating system generates a corresponding text cache and renders the text with a smaller size.
[0065] See also Figure 1C As shown in the figure, when the user ends touching the application icon, that is, the user's finger leaves the display screen area corresponding to the application icon, the dynamic effect of the application icon and text is that the size of the icon and text (such as the size of the icon, the font size of the text, etc.) gradually increases. At this time, the operating system generates a corresponding text buffer and renders texts of different font sizes.
[0066] When the operating system determines the dynamic effect of the text and renders the text, it needs to write the text cache into the system's cache space or needs to search in the cache space whether there is a text cache corresponding to the text to be rendered. However, the memory occupied by the text cache in the system's cache space usually has a pre-set upper limit. When the sum of the memory required by the text cache to be written and the memory already occupied by the text cache in the current cache space reaches an upper limit, or after finding the text cache corresponding to the text to be rendered, it is determined that the memory occupied by the text cache in the current cache space exceeds the upper limit, in order to continue writing the text cache or return the found text cache, it is necessary to trigger the cache cleanup mechanism to clean up the text cache in the current cache space to reduce the memory occupied by the text cache in the current cache space.
[0067] See also Figure 2 As shown, after the text cache cleaning operation is triggered, the cache cleaning task is added to the rendering thread, and the text data to be cleaned is deleted from the hash table ( Figure 2 In the rendering thread, the cache cleaning task is added to the rendering thread, and the rendering thread can write the new text cache into the system's cache space and render the text and other content on the application interface only after the cache cleaning task is completed. In the rendering thread, the execution of the cache cleaning task will increase the time consumption of the rendering thread, resulting in the inability to draw, render and display the application interface to be displayed in time, causing the system to freeze, thereby affecting the user experience.
[0068] See also Figure 3 As shown, it is a software architecture diagram of the electronic device provided in the embodiment of the present application. The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. For example, the Android system is divided into four layers, from top to bottom, namely, the application layer 101, the framework layer 102, the Android runtime (Androidruntime) and system library 103, the hardware abstraction layer 104, and the kernel layer 105.
[0069] The application layer can include a series of application packages. For example, an application package can include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, device control service, etc.
[0070] The framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions. For example, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc.
[0071] Among them, the window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make the data accessible to the application. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build applications. The display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying pictures. The phone manager is used to provide communication functions for electronic devices. For example, the management of call status (including connected, hung up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify the completion of downloads, message reminders, etc. The notification manager can also be a notification that appears in the top status bar of the system in the form of an icon or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0072] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system. The core library contains two parts: one is the function that the Java language needs to call, and the other is the Android core library.
[0073] The application layer and framework layer run in the virtual machine. The virtual machine executes the java files of the application layer and framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0074] The system library may include multiple functional modules, such as a surface manager, a media library, a 3D graphics processing library (such as OpenGL ES), a 2D graphics engine (such as SGL), etc.
[0075] Among them, the surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of multiple commonly used audio and video formats, as well as static image files. The media library can support multiple audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing. The 2D graphics engine is a drawing engine for 2D drawing.
[0076] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0077] The kernel layer is the core of the operating system of an electronic device. It is the first layer of software expansion based on hardware. It provides the most basic functions of the operating system and is the basis for the operation of the operating system. It is responsible for managing the system's processes, memory, device drivers, files, and network systems, and determines the performance and stability of the system. For example, the kernel can determine the operating time of an application on a certain part of the hardware.
[0078] The kernel layer includes programs that are closely related to the hardware, such as interrupt handlers, device drivers, etc. It also includes basic, common, and high-frequency modules, such as clock management modules, process scheduling modules, etc. It also includes key data structures. The kernel layer can be set in the processor or solidified in the internal memory.
[0079] See also Figure 4 FIG. 1 is a flow chart of a cache management method provided by an embodiment of the present application. The method is applied in an electronic device, and the cache management method includes:
[0080] S101, in response to a text rendering instruction, obtaining a text data block corresponding to the text to be rendered.
[0081] In one embodiment of the present application, in response to a text rendering instruction, a detailed process of generating a text data block is as follows: Figure 5 As shown, specifically including:
[0082] S1011, generating a rendering instruction in response to a change in the display interface.
[0083] In one embodiment of the present application, the hardware abstraction layer 104 includes a drawing rendering service (SurfaceFlinger) 1041. In response to the change of the display interface, generating a drawing rendering instruction includes: in response to the change of the display interface triggered by the user's touch operation or the change of the display interface triggered automatically, the application sends a rendering request instruction to the drawing rendering service 1041, the drawing rendering service 1041 responds to the rendering request instruction, sends a rendering signal to the application, and the application responds to the rendering signal and generates a rendering instruction. Among them, the rendering signal can be a vsync signal.
[0084] In one embodiment of the present application, when the display interface changes, the changed display interface needs to be presented to the user through the display screen, that is, the application needs to draw and render the changed display interface. In order to trigger the drawing and rendering process, a rendering request instruction needs to be generated to request a rendering signal. For example, the user's touch operation may include the operation of clicking an application icon to start the application, the operation of scrolling the application interface by sliding the display screen up and down, and the operation of switching the application interface by sliding the display screen left and right. The above touch operations can trigger changes in the display interface, and the application generates a drawing request instruction in response to the touch operation.
[0085] For another example, when the display interface includes content that is automatically switched or scrolled, or when a user uses an electronic device to play a video or play a game, the change in the display interface can be automatically triggered, thereby generating a rendering request instruction.
[0086] S1012, in response to the rendering instruction, determine whether the display interface to be rendered contains text. If the display interface to be rendered contains text, the process proceeds to S1013; if the display interface to be rendered does not contain text, the process returns to S1011.
[0087] In an embodiment of the present application, in response to a rendering instruction, determining whether the display interface to be rendered contains text includes: in response to the rendering instruction, obtaining the content of each window in the display interface to be rendered, identifying whether the content of each window contains text, if the content of any window contains text, determining that the display interface to be rendered contains text, and if the content of all windows does not contain text, determining that the display interface to be rendered does not contain text.
[0088] Since the embodiments of the present application focus on describing the processing of the text cache generated during the text rendering process, and the rendering of other content such as graphics is not the focus of this embodiment, therefore, when it is determined that the display interface to be rendered does not contain text, the rendering of other content is not described in detail, and the process returns to S1011 to continue detecting changes in the display interface, and subsequent processes are only executed when the display interface to be rendered contains text.
[0089] S1013, generate a text rendering instruction, and in response to the text rendering instruction, create or find a text data block corresponding to the text to be rendered.
[0090] In an embodiment of the present application, in an electronic device, the text data block is a strike, which records the attributes of a character. The attributes of the character may include the character content, font size, color, etc., and each text data block corresponds to a character. For example, as Figure 1A shown, the characters "阅" and "读" in the reading application name respectively correspond to a text data block. The text data block corresponding to the character "阅" records the character content "阅" and the font size and color of the character "阅".
[0091] In an embodiment of the present application, creating or finding a text data block corresponding to the text to be rendered includes: obtaining at least one character in the display interface to be rendered, checking whether the cache space contains the text data block corresponding to at least one character in the display interface to be rendered, if it is found that the cache space contains the text data block corresponding to at least one character in the display interface to be rendered, obtaining the text data block corresponding to at least one character in the display interface to be rendered from the cache space; if it is not found that the cache space contains the text data block corresponding to any character in the display interface to be rendered, creating a text data block corresponding to the any character based on the attributes of the any character to be rendered, that is, the created text data block has the attributes of the any character to be rendered.
[0092] For example, as Figure 1C shown, in response to the text rendering instruction, for Figure 1C When rendering the two words "read" in the interface, if the text data blocks corresponding to the words "read" and "read" are not found in the cache space of the electronic device, a text data block corresponding to the word "read" is created based on the attributes of the word "read" to be rendered, and a text data block corresponding to the word "read" is created based on the attributes of the word "read" to be rendered.
[0093] S102, judging whether the current text cache meets the preset cache cleaning condition. If the current text cache meets the preset cache cleaning condition, the process enters S103; if the current text cache does not meet the preset cache cleaning condition, the process returns to S101.
[0094] In the process of text rendering, after creating a text data block based on the text to be rendered, it is necessary to write the created text data block into the cache space of the electronic device, so that the text data block forms a text cache in the cache space, and obtain the text data block from the cache space, and perform text rendering based on the text data block. Alternatively, when the text data block corresponding to the text to be rendered is found in the cache space, the text data block is obtained from the cache space, and the text rendering is performed based on the text data block. In addition, after obtaining the text data block, the operation data of the text is also written into the corresponding text data block, and the operation data of the text may include image data, moving path data, etc. For example, when it is necessary to set an image for the text corresponding to the text data block, or when the text corresponding to the text data block needs to move with the sliding of the display interface, the image data and moving path data of the text will be written into the text data block corresponding to the text, so that the memory occupied by the text data block in the cache space increases. Therefore, when the operation data of the corresponding text is written into the text data block, it is also determined whether the current text cache meets the preset cache cleaning condition, and the cleaning operation of the text cache is triggered based on the current text cache meeting the preset cache cleaning condition.
[0095] In one embodiment of the present application, determining whether the current text cache satisfies the preset cache cleaning condition includes: when the text data block corresponding to the text to be rendered is found in the cache space, or when the text data block corresponding to the text to be rendered is created and the created text data block is written into the cache space, determining whether the memory occupied by the text data block in the current cache space is greater than or equal to the memory threshold; if the memory occupied by the text data block in the current cache space is greater than or equal to the memory threshold, determining that the current text cache satisfies the preset cache cleaning condition; if the memory occupied by the text data block in the current cache space is less than the memory threshold, determining that the current text cache does not satisfy the preset cache cleaning condition. Among them, the memory threshold is the upper limit of the memory occupied by the text cache in the cache space, which can be 16777216B. In other embodiments, the memory threshold can also be set to other appropriate values as required.
[0096] If the current text cache does not meet the preset cache cleaning condition, it can be determined that the current cache space of the electronic device is sufficient and there is no need to clean the text cache. The process returns to S101 to continue detecting text rendering instructions.
[0097] S103, determining the memory occupied by the text data block to be cleared.
[0098] In one embodiment of the present application, determining the memory occupied by the text data blocks to be cleared includes: if the memory occupied by the text data blocks in the current cache space is greater than or equal to the memory threshold, determining the memory difference between the memory occupied by the text data blocks in the current cache space and the memory threshold, that is, determining the portion of the memory occupied by the text data blocks in the current cache space that exceeds the memory threshold, judging whether the memory difference is greater than the preset text cache memory space, if the memory difference is greater than the preset text cache memory space, determining that the memory occupied by the text data blocks to be cleared is at least the memory difference; if the memory difference is less than or equal to the preset text cache memory space, determining that the memory occupied by the text data blocks to be cleared is at least the preset text cache memory space. Among them, the preset text cache memory space is one quarter of the memory occupied by the text data blocks in the current cache space. In other embodiments, the preset text cache memory space can also be set to other suitable values according to requirements.
[0099] The cache clearing mechanism of the embodiment of the present application is to release at least one quarter of the memory space occupied by the text data block when the memory occupied by the text data block in the cache space exceeds the upper limit, thereby ensuring that the created or found text data block can be returned to the drawing rendering service and avoiding cache space overflow.
[0100] S104, obtaining the text data blocks to be cleaned from the cache space based on the memory occupied by the text data blocks to be cleaned.
[0101] In one embodiment of the present application, obtaining the text data blocks to be cleaned from the cache space includes: obtaining the text data blocks with the earliest write time and which are not in use from the cache space one by one as the text data blocks to be cleaned, until the memory occupied by all the obtained text data blocks to be cleaned is greater than or equal to the memory occupied by the determined text data blocks to be cleaned.
[0102] See also Figure 6 As shown, it is a schematic diagram of the status of the text data blocks in the cache space provided by the embodiment of the present application. The text data blocks are written into the cache space in sequence based on the time sequence, and the multiple text data blocks are arranged in the time sequence of writing into the cache space. The earliest written text data block is at the tail of the queue, and the text data blocks that can be cleaned are obtained from the tail. For example, in the cache space, the text data block A has the earliest writing time, but the text data block A is in use and cannot be cleaned; except for the text data block A, the text data block B has the earliest writing time, and the text data block B is in an unused state and can be cleaned; except for the text data blocks A and B, the text data block C has the earliest writing time, and the text data block C is in an unused state and can be cleaned. Based on the above rules, the text data blocks with the earliest writing time and in an unused state are obtained one by one in the cache space as the text data blocks to be cleaned.
[0103] In another embodiment of the present application, obtaining the text data blocks to be cleaned from the cache space includes: obtaining the text data blocks with the longest idle time one by one from the cache space as the text data blocks to be cleaned, until the memory occupied by all the obtained text data blocks to be cleaned is greater than or equal to the memory occupied by the determined text data blocks to be cleaned. The text data block with the longest idle time is the text data block that has not been used for the longest time.
[0104] S105, setting the text data block to be cleaned to a use state.
[0105] In one embodiment of the present application, setting the text data block to be cleaned up to a use state includes: triggering a cache cleanup operation, setting a shared pointer to point to a storage address of the text data block to be cleaned up, so that the shared pointer references the text data block to be cleaned up, thereby setting the text data block to be cleaned up to a use state. The storage address of the text data block to be cleaned up is the storage address of the text data block to be cleaned up in the cache space.
[0106] S106, creating a background thread, setting the text data block to be cleaned up to an unused state in the background thread, and releasing the memory space occupied by the text data block to be cleaned up.
[0107] In one embodiment of the present application, a detailed process of creating a background thread, setting the text data block to be cleaned up to an unused state in the background thread, and releasing the memory space occupied by the text data block to be cleaned up is as follows: Figure 7 As shown, specifically including:
[0108] S1061, delete the record associated with the text data block to be cleaned in the hash table.
[0109] In one embodiment of the present application, each text data block corresponds to a data unit StrikeSpec, which is used to record the attributes of the text data block. Each data unit has a corresponding descriptor. During the text rendering process, after obtaining the text data block corresponding to the text to be rendered, the descriptor of the data unit corresponding to the text data block is used as the key key, and the shared pointer pointing to the text data block is recorded in the hash table as the value value, that is, the data unit corresponding to the text data block and the shared pointer pointing to the text data block are recorded in the hash table in the form of a key-value pair.
[0110] In one embodiment of the present application, deleting records associated with a text data block to be cleaned in a hash table includes: determining a descriptor of a data unit corresponding to the text data block to be cleaned, identifying a record with the descriptor as a key in the hash table, obtaining records associated with the text data block to be cleaned, and deleting the key-value pair (i.e., key and value) record corresponding to the descriptor, thereby deleting the records associated with the text data block to be cleaned.
[0111] S1062, creating a background thread, and adding the operation of setting the text data block to be cleaned up to an unused state and the operation of releasing the memory space occupied by the text data block to be cleaned up to a task queue of the background thread.
[0112] See also Figure 8 As shown, it is a schematic diagram of a background thread provided by an embodiment of the present application. In an embodiment of the present application, a background thread is created through a Runnable interface, a Callable interface or a Future interface. The operation of setting the text data block to be cleaned up to an unused state is a reset operation of a shared pointer, which is used to reset the shared pointer and set the text data block to be cleaned up to an unused state so that the text data block can be cleaned up.
[0113] S1063, running a background thread, setting the text data block to be cleaned up to an unused state, and releasing the memory space occupied by the text data block to be cleaned up.
[0114] In one embodiment of the present application, a background thread is run to execute tasks in the task queue of the background thread, and a reset operation of a shared pointer is first performed to reset the shared pointer, thereby setting the text data block to be cleaned to an unused state. Then, an operation of releasing the memory space occupied by the text data block to be cleaned is performed to delete the text data block to be cleaned from the cache space, thereby releasing the memory space occupied by the text data block to be cleaned.
[0115] Specifically, after deleting the key-value pair record of the descriptor of the data unit corresponding to the text data block to be cleaned and the shared pointer pointing to the text data block, the shared pointer pointing to the text data block is reset. After resetting the shared pointer, the text data block pointed to by the shared pointer is in an unreferenced state, that is, in an unused state, so the memory occupied by the text data block can be released.
[0116] In one embodiment of the present application, after a preset time after adding the reset operation of the shared pointer and the operation of releasing the memory space occupied by the text data block to be cleaned to the task queue of the background thread, the background thread is run to release the memory space occupied by the text data block to be cleaned. The preset time is 1 second. In other embodiments, the preset time can also be set to other appropriate time according to requirements.
[0117] In another embodiment of the present application, the background thread can also be processed by the small core of the processor to reduce the power consumption of the device and realize multi-core scheduling of cache cleaning.
[0118] In another embodiment of the present application, the cache management method further includes: in response to a preset operation on the application, releasing the memory space occupied by the text data block of the application in the cache space. The preset operation on the application may be closing the application or setting the application to run in the background.
[0119] like Figure 2 As shown, in the original text cache cleaning mechanism, when the text cache cleaning operation is triggered, after deleting the record associated with the text data block to be cleaned from the hash table, the memory occupied by the text data block to be cleaned will be released immediately. In this way, the text cache cleaning operation will still be executed in the rendering thread. Therefore, in an embodiment of the present application, after the text data block to be cleaned is determined, the text data block to be cleaned is set to a used state through a shared pointer, and the text data block in the used state cannot be cleaned. In this way, after creating a background thread, and adding the operation of setting the text data block to be cleaned to an unused state and the operation of releasing the memory space occupied by the text data block to be cleaned to the task queue of the background thread, the task of the background thread is executed, thereby releasing the memory space occupied by the text data block to be cleaned.
[0120] See also Fig. 9 FIG. 1 is a flow chart of a cache management method provided by another embodiment of the present application. The method is applied in an electronic device, and the cache management method includes:
[0121] S201, in response to a text rendering instruction, obtaining a text data block corresponding to the text to be rendered.
[0122] S202, judging whether the current text cache meets the preset cache cleaning condition. If the current text cache meets the preset cache cleaning condition, the process enters S203; if the current text cache does not meet the preset cache cleaning condition, the process returns to S201.
[0123] S203, determining the memory occupied by the text data block to be cleared.
[0124] S204, obtaining a text data block to be cleared from the cache space.
[0125] In another embodiment of the present application, obtaining a text data block to be cleared from the cache space includes: obtaining a text data block with the earliest write time and in an unused state from the cache space.
[0126] S205, setting the text data block to be cleaned to a use state.
[0127] S206, creating a background thread, setting the text data block to be cleaned up to an unused state in the background thread, and releasing the memory space occupied by the text data block to be cleaned up.
[0128] S207, determine whether the released memory space reaches the occupied memory of the text data block to be cleared. If the released memory space reaches the occupied memory of the text data block to be cleared, the process returns to S201; if the released memory space does not reach the occupied memory of the text data block to be cleared, the process returns to S204.
[0129] The specific implementation of steps S201 - S203 , S205 - S206 is the same as the specific implementation of steps S101 - S103 , S105 - S106 , and will not be repeated here.
[0130] See also Fig.10 FIG. 1 is a flow chart of a cache management method provided by another embodiment of the present application. The method is applied in an electronic device, and the cache management method includes:
[0131] S301, in response to a text rendering instruction, obtaining a text data block corresponding to the text to be rendered.
[0132] S302, judging whether the current text cache meets the preset cache cleaning condition. If the current text cache meets the preset cache cleaning condition, the process enters S303; if the current text cache does not meet the preset cache cleaning condition, the process returns to S301.
[0133] In another embodiment of the present application, determining whether the current text cache satisfies a preset cache cleaning condition includes: when a text data block corresponding to the text to be rendered is found in the cache space, or when a text data block corresponding to the text to be rendered is created and the created text data block is written into the cache space, determining whether the memory occupied by the text data blocks in the current cache space is greater than or equal to the memory threshold, and determining whether the number of text data blocks in the current cache space is greater than or equal to the number threshold; if the memory occupied by the text data blocks in the current cache space is greater than or equal to the memory threshold, and / or the number of text data blocks in the current cache space is greater than or equal to the number threshold, determining that the current text cache satisfies the preset cache cleaning condition; if the memory occupied by the text data blocks in the current cache space is less than the memory threshold, and the number of text data blocks in the current cache space is less than the number threshold, determining that the current text cache does not satisfy the preset cache cleaning condition.
[0134] If the current text cache does not meet the preset cache cleaning condition, it can be determined that the current cache space of the electronic device system is sufficient and there is no need to clean the text cache. The process returns to S301 to continue detecting text rendering instructions.
[0135] S303, determining the memory occupied and / or the number of the text data blocks to be cleared.
[0136] In another embodiment of the present application, determining the occupied memory and / or number of the text data blocks to be cleared includes: if the occupied memory of the text data blocks in the current cache space is greater than or equal to the memory threshold, determining the memory difference between the occupied memory of the text data blocks in the current cache space and the memory threshold, that is, determining the portion of the occupied memory of the text data blocks in the current cache space that exceeds the memory threshold, judging whether the memory difference is greater than the preset text cache memory space, if the memory difference is greater than the preset text cache memory space, determining that the occupied memory of the text data blocks to be cleared is at least the memory difference; if the memory difference is less than or equal to the preset text cache memory space, determining that the occupied memory of the text data blocks to be cleared is at least the preset text cache memory space. Among them, the preset text cache memory space is one quarter of the memory occupied by the text data blocks in the current cache space. In other embodiments, the preset text cache memory space can also be set to other suitable values according to requirements.
[0137] In another embodiment of the present application, determining the memory occupied and / or number of text data blocks to be cleared further includes: if the number of text data blocks in the current cache space is greater than or equal to the number threshold, determining the number difference between the number of text data blocks in the current cache space and the number threshold, that is, determining the number of text data blocks in the current cache space that exceed the number threshold, judging whether the number difference is greater than the preset number of text data blocks, if the number difference is greater than the preset number of text data blocks, determining that the number of text data blocks to be cleared is at least the number difference; if the number difference is less than or equal to the preset number of text data blocks, determining that the number of text data blocks to be cleared is at least the preset number of text data blocks. Wherein, the preset number of text data blocks is one-fourth of the total number of text data blocks in the current cache space. In other embodiments, the preset number of text data blocks can also be set to other suitable values as required.
[0138] In another embodiment of the present application, determining the occupied memory and / or the number of text data blocks to be cleared further includes: if the occupied memory of the text data blocks in the current cache space is greater than or equal to the memory threshold, and the number of text data blocks in the current cache space is greater than or equal to the number threshold, determining the memory difference between the occupied memory of the text data blocks in the current cache space and the memory threshold, that is, determining the portion of the occupied memory of the text data blocks in the current cache space that exceeds the memory threshold; determining the quantity difference between the number of text data blocks in the current cache space and the quantity threshold, that is, determining the number of text data blocks in the current cache space that exceeds the quantity threshold; judging whether the memory difference is greater than a preset text cache memory space, and judging whether the quantity difference is greater than a preset number of text data blocks; if the memory difference is greater than the preset text cache memory space, and the quantity difference is greater than the preset number of text data blocks, determining the occupied memory of the text data blocks to be cleared. The memory occupied by the text data blocks to be cleaned is at least the memory difference, and the number of text data blocks to be cleaned is determined to be at least the number difference; if the memory difference is greater than the preset text cache memory space, and the number difference is less than or equal to the preset number of text data blocks, it is determined that the memory occupied by the text data blocks to be cleaned is at least the memory difference, and the number of text data blocks to be cleaned is at least the preset number of text data blocks; if the memory difference is less than or equal to the preset text cache memory space, and the number difference is greater than the preset number of text data blocks, it is determined that the memory occupied by the text data blocks to be cleaned is at least the preset text cache memory space, and the number of text data blocks to be cleaned is determined to be at least the number difference; if the memory difference is less than or equal to the preset text cache memory space, and the number difference is less than or equal to the preset number of text data blocks, it is determined that the memory occupied by the text data blocks to be cleaned is at least the preset text cache memory space, and the number of text data blocks to be cleaned is at least the preset number of text data blocks.
[0139] In another embodiment of the present application, when determining that the occupied memory of the text data blocks to be cleaned is at least the memory difference, and determining that the number of text data blocks to be cleaned is at least the number difference, if the memory difference is greater than or equal to the occupied memory of the number of text data blocks to be cleaned corresponding to the number difference, then the number of text data blocks to be cleaned is greater than the number difference, so as to satisfy that the occupied memory of the cleaned text data blocks is at least the memory difference; if the number difference is greater than or equal to the number of text data blocks to be cleaned corresponding to the occupied memory of the memory difference, then the occupied memory of the text data blocks to be cleaned is greater than the memory difference, so as to satisfy that the number of cleaned text data blocks is at least the number difference. In other words, the text data blocks actually cleaned need to satisfy both the cleaning condition of the occupied memory and the cleaning condition of the number.
[0140] For example, the quantity threshold is 2048, the memory threshold is 16777216B, and in the initial state, the text cache in the cache space occupies 16777000B of memory, and the number of text caches is 293. After creating a text data block that occupies 300B of memory, if the created text data block is written into the cache space, the text cache occupies 16777300B of memory, and the number of text caches is 294. At this time, the memory occupancy exceeds 84B (that is, the memory occupied by the text cache exceeds 84B compared to the memory threshold), and one quarter of the current occupied memory is 4194325B. Obviously, the excess memory is less than the preset text cache memory space. Therefore, it is determined that the memory occupied by the text data block to be cleared is at least the preset text cache memory space, that is, 4194325B of the memory space occupied by the text cache is released. Finally, 132 text caches were released, corresponding to 4416193B of space. After the release, the text caches occupied 12361107B of memory, and the number of text caches was 162.
[0141] For another example, the quantity threshold is 2048, the memory threshold is 16777216B, and in the initial state, the memory occupied by the text cache in the cache space is 16000000B, and the number of text caches is 293. After adding images to some text data blocks, the occupied memory increases to 25000000B, and the number of text caches remains 293. After finding the text cache, it is determined that the memory occupancy exceeds 8222784B (that is, the memory occupied by the text cache exceeds 8222784B compared to the memory threshold), and one quarter of the current occupied memory is 6250000B. Obviously, the excess memory is greater than the preset text cache memory space. Therefore, it is determined that the memory occupied by the text data block to be cleaned is at least the excess text cache memory space, that is, 8222784B of the memory space occupied by the text cache is released. Finally, 250 text caches were released, corresponding to 8230000B of space. After the release, the text caches occupied 16770000B of memory, and the number of text caches was 43.
[0142] According to the above examples, the cache clearing mechanism of the embodiment of the present application is to release at least one quarter of the memory space occupied by the text data blocks when the memory occupied by the text data blocks in the cache space exceeds the upper limit, and to release at least one quarter of the memory space occupied by the text data blocks when the number of text data blocks in the cache space exceeds the upper limit. This ensures that the created or found text data blocks can be returned to the drawing and rendering service and avoids cache space overflow.
[0143] S304, obtaining the text data blocks to be cleaned from the cache space based on the memory occupied and / or the number of the text data blocks to be cleaned.
[0144] In another embodiment of the present application, obtaining text data blocks to be cleaned from the cache space includes: obtaining text data blocks with the earliest write time and that are not in use from the cache space one by one as text data blocks to be cleaned, until the memory occupied by all the obtained text data blocks to be cleaned is greater than or equal to the memory occupied by the determined text data blocks to be cleaned, and / or the number of all the obtained text data blocks to be cleaned is greater than or equal to the determined number of text data blocks to be cleaned.
[0145] In other embodiments of the present application, obtaining the text data blocks to be cleaned from the cache space includes: obtaining the text data blocks with the longest idle time one by one from the cache space as the text data blocks to be cleaned, until the memory occupied by all the obtained text data blocks to be cleaned is greater than or equal to the memory occupied by the determined text data blocks to be cleaned, and / or the number of all the obtained text data blocks to be cleaned is greater than or equal to the determined number of text data blocks to be cleaned. Among them, the text data block with the longest idle time is the text data block that has not been used for the longest time.
[0146] S305, setting the text data block to be cleaned to a use state.
[0147] S306, creating a background thread, setting the text data block to be cleaned up to an unused state in the background thread, and releasing the memory space occupied by the text data block to be cleaned up.
[0148] The specific implementation of steps S301, S305-S306 is the same as the specific implementation of steps S101, S105-S106, and will not be repeated here.
[0149] See also Fig.11 FIG. 1 is a flow chart of a cache management method provided by another embodiment of the present application. The method is applied in an electronic device, and the cache management method includes:
[0150] S401, creating or searching for a text data block.
[0151] S402, determine whether the memory and number of the current font cache have reached the upper limit. If the memory and number of the current font cache have reached the upper limit, the process proceeds to S403; if the memory and number of the current font cache have not reached the upper limit, the process returns to S401.
[0152] S403, calculating the number of font caches and memory space that need to be released.
[0153] S404, starting from the end, obtaining the text data block that can be released.
[0154] S405, resource release, releasing the memory space occupied by the text data block.
[0155] In another embodiment of the present application, the detailed process of releasing the memory space occupied by the text data block is as follows: Fig.12 As shown, specifically including:
[0156] S4051, triggering the font cache cleanup operation for the first time.
[0157] S4052, adding a shared pointer to point to the font data block to be cleaned up.
[0158] S4053, deleting the font data block to be cleaned up from the hash table.
[0159] S4054, create a background thread, and add the reset operation of the shared pointer to the queue of the background thread.
[0160] S4055, execute background thread.
[0161] S4056, releasing the memory space occupied by the text data blocks in batches.
[0162] In another embodiment of the present application, when the font cache cleaning operation is triggered again, S4051-S4052 are repeatedly executed.
[0163] S406, judging whether the released memory space and the number of font caches meet the conditions. If the released memory space and the number of font caches meet the conditions, the process proceeds to S407; if the released memory space and the number of font caches do not meet the conditions, the process returns to S404.
[0164] S407, rendering the text based on the created or searched text data block.
[0165] In the embodiment of the present application, each time a text data block is created or searched, it is checked whether the number of current font caches and the memory space occupied have reached the upper limit. If the upper limit has been reached, the font cache cleanup operation will be triggered, and the cleanup will start from the tail text data block until the released memory space and number meet the requirements. When the number of font caches and the memory space occupied reach the upper limit, in theory, text data blocks can still be created, but in order to avoid the font cache being too large to affect the search efficiency and the entire machine memory, the text data block created or searched is returned only after the cleanup operation is completed.
[0166] In order to avoid the cleanup operation taking too long and affecting the entire rendering thread, the release of the text data block resources is performed in the background thread. Figure 2 The "resource release" in the process is changed to "adding the resource release task to the background thread", that is, the cleanup action is changed to the task queue action, avoiding the impact of the cleanup action on the time consumption of the rendering thread. Fig.12 In the process, there is no need to wait for resources to be released. You only need to wait for the records associated with the text data block to be discarded to be deleted from the hash table. After adding the operation of releasing the memory space occupied by the text data block to the background thread, you can apply for cache resources to draw and render new text data blocks. At the same time, in order to avoid too frequent resource release actions of the background thread, the method of letting the work queue wait for 1 second before releasing in batches is adopted.
[0167] In order to solve the problem that the application interface cannot be updated and displayed in time due to the increase in the time consumption of the rendering thread caused by the processing of the cache cleaning task, the embodiment of the present application also provides an electronic device. Fig.13 As shown, the electronic device 100 can be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, an artificial intelligence (AI) device, a wearable device, a vehicle-mounted device, a smart home device and / or a smart city device. The embodiments of the present application do not impose any special restrictions on the specific type of the electronic device 100.
[0168] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a Universal Serial Bus (USB) interface 130, a charging 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, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a Subscriber Identification Module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0169] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0170] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0171] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0172] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0173] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an Inter-integrated Circuit (I2C) interface, an Inter-integrated Circuit Sound (I2S) interface, a Pulse Code Modulation (PCM) interface, a Universal Asynchronous Receiver / Transmitter (UART) interface, a Mobile Industry Processor Interface (MIPI), a General-Purpose Input / Output (GPIO) interface, a Subscriber Identity Module (SIM) interface, and / or a Universal Serial Bus (USB) interface, etc.
[0174] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface to realize the touch function of the electronic device 100.
[0175] The I2S interface can be used for audio communication.
[0176] The PCM interface can also be used for audio communication to sample, quantize and encode analog signals.
[0177] The UART interface is a universal serial data bus used for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication.
[0178] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the display screen 194 communicate via the DSI interface to realize the display function of the electronic device 100.
[0179] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or a data signal.
[0180] The USB interface 130 is an interface that complies with USB standard specifications, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
[0181] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0182] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0183] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, Microled, Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0184] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0185] The internal memory 121 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM).
[0186] Random access memory may include static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM, for example, the fifth generation DDR SDRAM is generally referred to as DDR5 SDRAM), etc.;
[0187] Non-volatile memory may include disk storage devices and flash memory.
[0188] Flash memory can be divided into NOR FLASH, NAND FLASH, 3D NAND FLASH, etc. according to the operating principle. It can be divided into single-level cell (SLC), multi-level cell (MLC), triple-level cell (TLC), quad-level cell (QLC), etc. according to the storage unit potential level. It can be divided into universal flash storage (UFS), embedded Multi Media Card (eMMC), etc. according to the storage specification.
[0189] The random access memory can be directly read and written by the processor 110, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data.
[0190] The non-volatile memory may also store executable programs and user and application data, etc., and may be loaded into the random access memory in advance for direct reading and writing by the processor 110 .
[0191] The external memory interface 120 can be used to connect to an external non-volatile memory to expand the storage capacity of the electronic device 100. The external non-volatile memory communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos are stored in the external non-volatile memory.
[0192] The internal memory 121 or the external memory interface 120 is used to store one or more computer programs. The one or more computer programs are configured to be executed by the processor 110. The one or more computer programs include multiple instructions. When the multiple instructions are executed by the processor 110, the cache management method executed on the electronic device 100 in the above embodiment can be implemented to realize the handwriting input display function of the electronic device 100.
[0193] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
[0194] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0195] An embodiment of the present application also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on the electronic device 100, the electronic device 100 executes the above-mentioned related method steps to implement the cache management method in the above-mentioned embodiment.
[0196] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement the cache management method in the above-mentioned embodiment.
[0197] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory so that the chip executes the cache management method in the above-mentioned method embodiments.
[0198] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.
[0199] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0200] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0201] The unit described as a separate component may or may not be physically separated, and the component shown as a unit may be one physical unit or multiple physical units, that is, it may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
[0202] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0203] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.
[0204] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.< / canvas> < / video> < / videoview> < / imgview> < / textview>
Claims
1. A cache management method, characterized in that: The method comprises: In response to the text rendering instruction, obtaining a text data block corresponding to the text to be rendered; Determine whether the current text cache meets the preset cache clearing conditions; If the current text cache meets the preset cache cleaning condition, determine the memory occupied by the text data block to be cleaned; Acquire the text data block to be cleaned from the cache space based on the memory occupied by the text data block to be cleaned; By setting a shared pointer to point to the storage address of the text data block to be cleaned, the shared pointer references the text data block to be cleaned, and sets the text data block to be cleaned to a use state; Create a background thread, set the text data block to be cleaned to an unused state in the background thread, and release the memory space occupied by the text data block to be cleaned, including: adding the operation of setting the text data block to be cleaned to an unused state and the operation of releasing the memory space occupied by the text data block to be cleaned to the task queue of the background thread; run the background thread, set the text data block to be cleaned to an unused state, and release the memory space occupied by the text data block to be cleaned.
2. The cache management method according to claim 1, characterized in that: The operation of setting the text data block to be cleaned up to an unused state is an operation of resetting the shared pointer.
3. The cache management method according to claim 1, characterized in that: The method further comprises: The descriptor of the data unit corresponding to the acquired text data block is used as the key, and the shared pointer pointing to the text data block is recorded as the value in the hash table, wherein the data unit corresponds to the text data block one by one and is used to record the attributes of the text data block.
4. The cache management method according to claim 3, characterized in that: The method further comprises: Delete the record associated with the text data block to be cleaned in the hash table.
5. The cache management method according to claim 4, characterized in that: Deleting the record associated with the text data block to be cleaned in the hash table includes: Determine the descriptor of the data unit corresponding to the text data block to be cleaned, identify the key-value pair record with the descriptor as the key in the hash table, and delete the key-value pair record corresponding to the descriptor.
6. The cache management method according to claim 1, characterized in that: The step of obtaining the text data block corresponding to the text to be rendered in response to the text rendering instruction includes: In response to changes in the display interface, generating rendering instructions; In response to the rendering instruction, determining whether the display interface to be rendered contains text; If the display interface to be rendered includes text, the text rendering instruction is generated, and in response to the text rendering instruction, a text data block corresponding to the text to be rendered is created or searched.
7. The cache management method according to claim 6, characterized in that: In response to the rendering instruction, determining whether the display interface to be rendered includes text includes: In response to the rendering instruction, obtaining the content of each window in the display interface to be rendered, and identifying whether the content of each window contains text; If the content of any window includes text, determining that the display interface to be rendered includes text; or If the contents of all windows do not contain text, it is determined that the display interface to be rendered does not contain text.
8. The cache management method according to claim 6, characterized in that: The step of creating or searching for a text data block corresponding to the text to be rendered includes: Obtain at least one character in the display interface to be rendered, and search whether the cache space contains a character data block corresponding to the at least one character; If it is found that the cache space contains the character data block corresponding to the at least one character, the character data block corresponding to the at least one character is obtained from the cache space; or If the cache space is not found to contain a text data block corresponding to any text, a text data block corresponding to any text is created based on the attributes of the any text to be rendered.
9. The cache management method according to claim 1, characterized in that: The step of determining whether the current text cache meets a preset cache clearing condition includes: When a text data block corresponding to the text to be rendered is found in the cache space, or when a text data block corresponding to the text to be rendered is created and the created text data block is written into the cache space, it is determined whether the memory occupied by the text data block in the current cache space is greater than or equal to the memory threshold; If the memory occupied by the text data blocks in the current cache space is greater than or equal to the memory threshold, it is determined that the current text cache meets the preset cache clearing condition; or If the memory occupied by the text data blocks in the current cache space is less than the memory threshold, it is determined that the current text cache does not meet the preset cache cleaning condition.
10. The cache management method according to claim 9, characterized in that: Determining the memory occupied by the text data block to be cleared includes: If the memory occupied by the text data block in the current cache space is greater than or equal to the memory threshold, determine the memory difference between the memory occupied by the text data block in the current cache space and the memory threshold; Determining whether the memory difference is greater than a preset text cache memory space; If the memory difference is greater than the preset text cache memory space, determining that the memory occupied by the text data block to be cleared is at least the memory difference; or If the memory difference is less than or equal to the preset text cache memory space, it is determined that the memory occupied by the text data block to be cleared is at least the preset text cache memory space.
11. The cache management method according to claim 1, characterized in that: The acquiring the text data block to be cleaned from the cache space based on the memory occupied by the text data block to be cleaned includes: The text data blocks with the earliest writing time and in an unused state are obtained one by one from the cache space as the text data blocks to be cleaned, until the occupied memory of all the obtained text data blocks to be cleaned is greater than or equal to the determined occupied memory of the text data blocks to be cleaned.
12. The cache management method according to claim 1, wherein: The acquiring the text data block to be cleaned from the cache space based on the memory occupied by the text data block to be cleaned includes: The character data blocks with the longest idle time are obtained one by one from the cache space as the character data blocks to be cleaned up, until the memory occupied by all the obtained character data blocks to be cleaned up is greater than or equal to the determined memory occupied by the character data blocks to be cleaned up.
13. The cache management method according to claim 1, characterized in that: The method further comprises: In response to a preset operation on an application, the memory space occupied by the text data blocks of the application in the cache space is released.
14. The cache management method according to any one of claims 1 to 13, characterized in that: The text data block is used to record the attributes of the text to be rendered.
15. An electronic device, characterized in that: The electronic device comprises a memory and a processor: Wherein, the memory is used to store program instructions; The processor is used to read and execute the program instructions stored in the memory. When the program instructions are executed by the processor, the electronic device executes the cache management method according to any one of claims 1 to 14.
16. A chip coupled to a memory in an electronic device, characterized in that: The chip is used to control the electronic device to execute the cache management method according to any one of claims 1 to 14.
17. A computer storage medium, characterized in that: The computer storage medium stores program instructions, and when the program instructions are executed on an electronic device, the electronic device executes the cache management method according to any one of claims 1 to 14.
Citation Information
Patent Citations
Method and device for rendering characters
CN103186919A
Cleaning method and cleaning system for mobile terminal
CN105260319A
Method and terminal for managing program memory footprint
CN105824702A
Shared pointer pool-based message zero-copy processing method
CN106445838A
Cache line state
CN109614348A
