Data loading method, device, computer equipment and storage medium
By allowing the target data to be overloaded into memory when the terminal is in the target operation state, the problem of sharp increase in CPU usage is solved, the balanced use of memory and CPU is achieved, the frequency of heating of electronic devices is reduced, and the device life and user experience are improved.
Patent Information
- Application Number
- CN202111524292.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2041-12-14
AI Technical Summary
The existing data loading method has led to a sharp increase in CPU usage, which has damaged the life of electronic devices and brought bad experience to users.
By obtaining the amount of storage required to load the target data into memory, the ratio of the used storage in memory to the actual total available amount is calculated, and when the terminal is in the target operation state, the target data is allowed to be overloaded into memory to balance the use of memory and CPU.
It reduces the frequency of heating of electronic equipment and improves the service life and user experience of electronic equipment.
Smart Images

Figure CN114116231B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data loading technology, and in particular relates to a data loading method, apparatus, computer equipment and storage medium. Background Art
[0002] Electronic devices have limited hardware resources, making performance balancing crucial. Existing electronic devices are equipped with hardware such as disks, memory, and a CPU. When processing data, the CPU, based on data processing instructions, loads target data from disk into memory and then performs data processing based on the cached data in memory.
[0003] However, in specific applications, due to the limitations of memory capacity and the real-time available memory size, if the dynamically calculated remaining memory capacity is insufficient, the target data in the disk will be cached in the memory for a while, and the CPU will frequently read the target data from the disk in real time and cache it in the limited available storage space dynamically calculated in the memory. The data cached in the memory will be released while being processed to meet the data processing needs when the dynamically calculated remaining memory capacity is insufficient.
[0004] However, this processing method will cause the CPU usage to increase sharply in a short period of time. The increase in CPU usage will lead to increased power consumption of electronic devices, causing the electronic devices to overheat, which on the one hand will shorten the life of the electronic devices, and on the other hand will bring a bad user experience. Summary of the Invention
[0005] The embodiments of the present application provide a data loading method, apparatus, computer equipment, and storage medium to address the problem that existing data loading methods can cause CPU usage to rise sharply in a short period of time, which, on the one hand, damages the life of electronic equipment, and on the other hand, brings a poor user experience.
[0006] A first aspect of an embodiment of the present application provides a data loading method, comprising:
[0007] Obtaining a first target storage capacity required for loading target data into a memory in the terminal;
[0008] obtaining a remaining computational storage capacity of the memory, and when determining that the remaining computational storage capacity is less than the first target storage capacity, calculating a ratio of a sum of a used computational storage capacity of the memory and the first target storage capacity to an actual total available amount of the memory, to obtain a calculation result;
[0009] The remaining computing storage and the used computing storage are calculated based on a set available limit of the memory, and the set available limit is less than the actual total available amount;
[0010] Based on the calculation result, when it is determined that the terminal is in the target operating state, the target data is loaded into the memory.
[0011] Optionally, before obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the method further includes:
[0012] Obtaining first data to be loaded that currently needs to be loaded into the memory;
[0013] When the first data to be loaded meets the priority processing condition, determining that the first data to be loaded has memory excess allocation authority, and determining the first data to be loaded as the target data;
[0014] Among them, the priority processing conditions include: the first data to be loaded contains multiple sub-data and there is a data relationship between the sub-data that is output in sequence and in a circular manner, the first data to be loaded is data with a set processing priority, or the first data to be loaded corresponds to a user with set priority authority.
[0015] Optionally, before obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the method further includes:
[0016] Determining second data to be loaded that currently needs to be loaded into the memory;
[0017] When it is determined that the second data to be loaded is not the target data, obtaining a second target storage capacity required for loading the second data to be loaded into the memory;
[0018] Obtain the remaining computational storage capacity of the memory, and when determining that the remaining computational storage capacity is greater than the second target storage capacity, refuse to load the second data to be loaded into the memory until the remaining computational storage capacity is less than or equal to the second target storage capacity.
[0019] Optionally, when determining that the terminal is in a target operating state based on the calculation result, loading the target data into the memory includes:
[0020] Based on the calculation result, determining a magnitude relationship between the ratio and a first set threshold;
[0021] When it is determined that the ratio is less than or equal to a first set threshold, it is determined that the terminal is in the target operating state, and the target data is loaded into the memory.
[0022] Optionally, when determining that the terminal is in a target operating state based on the calculation result, loading the target data into the memory includes:
[0023] Based on the calculation result, determining a magnitude relationship between the ratio and a first set threshold;
[0024] When it is determined that the ratio is greater than the first set threshold, if it is determined that the ratio is less than a second set threshold, detecting the CPU usage of the terminal;
[0025] When the CPU usage is lower than a third set threshold, it is determined that the terminal is in the target operating state, and the target data is loaded into the memory.
[0026] Optionally, when it is determined based on the calculation result that the terminal is in the target operating state, after loading the target data into the memory, the method further includes:
[0027] In response to a call request for the target data from a target application in the terminal, reading the target data from the memory;
[0028] The read target data is output to the target application, and the target data is deleted from the memory.
[0029] Optionally, the target data includes a plurality of sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner, and outputting the read target data to the target application and deleting the target data from the memory includes:
[0030] According to the data relationship, each sub-data is cyclically output to the target application in sequence, and when it is detected that the target application ends calling the target data, the target data is deleted from the memory.
[0031] A second aspect of an embodiment of the present application provides a data loading device, including:
[0032] An acquisition module, configured to acquire a first target storage capacity required for loading target data into a memory in a terminal;
[0033] a calculation module, configured to obtain the remaining computing storage capacity of the memory, and when determining that the remaining computing storage capacity is less than the first target storage capacity, calculate the ratio of the sum of the used computing storage capacity of the memory and the first target storage capacity to the actual total available capacity of the memory, to obtain a calculation result; wherein the remaining computing storage capacity and the used computing storage capacity are calculated based on a set available limit of the memory, and the set available limit is less than the actual total available capacity;
[0034] A data loading module is configured to load the target data into the memory based on the calculation result when it is determined that the terminal is in a target operating state.
[0035] A third aspect of an embodiment of the present application provides a terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method described in the first aspect when executing the computer program.
[0036] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
[0037] A fifth aspect of the present application provides a computer program product, which, when executed on a terminal, enables the terminal to execute the steps of the method described in the first aspect.
[0038] As can be seen from the above, in an embodiment of the present application, by obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the remaining computational storage capacity of the memory is obtained, and when it is determined that the remaining computational storage capacity is less than the first target storage capacity, the ratio of the sum of the used computational storage capacity of the memory and the first target storage capacity to the actual total available amount of the memory is calculated, and finally when it is determined that the terminal is in the target operating state, the target data is loaded into the memory, and by comparing the target storage capacity required for the target data with the remaining computational storage capacity and the actual total available amount of the memory, a cache strategy that exceeds the remaining computational storage capacity of the memory is adopted, so that the target data realizes excess use of the memory in exchange for low CPU usage, and by balancing the use of memory and CPU, the frequency of heating of electronic devices is reduced, the service life of electronic devices is increased, and the user experience is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0040] Figure 1 This is a process of a data loading method provided in an embodiment of the present application Figure 1 ;
[0041] Figure 2 This is a process of a data loading method provided in an embodiment of the present application Figure 2 ;
[0042] Figure 3 This is a structural diagram of a data loading device provided in an embodiment of the present application;
[0043] Figure 4This is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.
[0045] It will be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0046] It should also be understood that the terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit the present application. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0047] It should be further understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0048] As used in this specification and the appended claims, the term "if" can be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0049] In specific implementations, the terminals described in the embodiments of the present application include, but are not limited to, other portable devices such as mobile phones, laptop computers, or tablet computers with touch-sensitive surfaces (e.g., touch screen displays and / or touch pads). It should also be understood that in some embodiments, the device is not a portable communication device, but a desktop computer with a touch-sensitive surface (e.g., touch screen displays and / or touch pads).
[0050] In the following discussion, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and / or joystick.
[0051] The terminal supports various applications, such as one or more of the following: a drawing application, a presentation application, a word processing application, a website creation application, a disk burning application, a spreadsheet application, a game application, a phone application, a video conferencing application, an email application, an instant messaging application, a workout support application, a photo management application, a digital camera application, a digital video camera application, a web browsing application, a digital music player application, and / or a digital video player application.
[0052] Various applications that can be executed on the terminal can use at least one common physical user interface device, such as a touch-sensitive surface. One or more functions of the touch-sensitive surface and corresponding information displayed on the terminal can be adjusted and / or changed between applications and / or within a corresponding application. In this way, the common physical architecture of the terminal (e.g., the touch-sensitive surface) can support a variety of applications with user interfaces that are intuitive and transparent to the user.
[0053] It should be understood that the size of the serial numbers of each step in this embodiment does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of this application.
[0054] In order to illustrate the technical solution described in this application, specific embodiments are provided below.
[0055] See also Figure 1 , Figure 1 This is a process of a data loading method provided in an embodiment of the present application Figure 1 .like Figure 1 As shown, a data loading method includes the following steps:
[0056] Step 101: Obtain a first target storage capacity required for loading target data into a memory in a terminal.
[0057] The target data is the set target data.
[0058] Specifically in one embodiment, the target data is data with memory excess allocation authority, so that the data loading method in this embodiment is executed based on the target data under the memory excess allocation authority.
[0059] On the one hand, the target data is specifically data corresponding to a higher processing priority. The higher processing priority is specifically manifested as:
[0060] The target data itself has a set processing priority, the target data corresponds to a processing task with a set priority, or the target data corresponds to a user with a set priority authority.
[0061] In specific applications, for example, system data may be set to a higher priority, while application loaded data may be set to a lower priority. The higher priority data may be granted memory excess allocation permission, while the lower priority data may not be granted memory excess allocation permission.
[0062] For some processing tasks, such as process scheduling tasks, they will be set to have a higher priority, and for display output tasks, they will be set to have a lower priority. The data involved in the higher priority processing tasks can be granted memory excess control permissions, and the data involved in the lower priority processing tasks will not be granted memory excess control permissions.
[0063] Correspondingly, different users also have different set priority permissions. For example, administrators have higher priority permissions, while ordinary users have lower priority permissions. Data associated with users with higher priority permissions can be granted memory excess control permissions, while data associated with users with lower priority permissions will not be granted memory excess control permissions.
[0064] In this case, it is necessary to identify this data as target data, grant it excess memory control permissions, and execute the data loading strategy in the subsequent process to ensure the normal operation of the system to the greatest extent possible.
[0065] On the other hand, the target data is specifically data that needs to be repeatedly loaded into the memory in a short period of time. Specifically,
[0066] The target data contains multiple sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner.
[0067] The target data includes, for example, GIF animations, music in loop playback mode, short videos on the Tik Tok platform, and other data.
[0068] Take GIF as an example, wherein the GIF contains a number of image frames, and these image frames need to be output in sequence and in a loop when the image is being viewed to achieve a dynamic playback effect of the FIG image.
[0069] For data with sequential, cyclical output characteristics, when memory space is insufficient for computation, image frames must be continuously and repeatedly read from disk. This cyclical reading process consumes more CPU resources, further exacerbating a sharp increase in CPU usage in a short period of time. In this case, these data with sequential, cyclical output characteristics can be identified as target data and granted memory overage permissions to execute data loading strategies in subsequent processes, minimizing excessive CPU resource usage in the short term.
[0070] On this basis, before executing step 101 to obtain the first target storage capacity required for loading the target data into the memory of the terminal, it is necessary to perform a permission check on the data to be loaded to determine whether it is the target data. After determining that it is the target data, the data loading method of this embodiment is executed. Specifically, it includes:
[0071] Obtain the first data to be loaded that currently needs to be loaded into the memory;
[0072] When the first data to be loaded meets the priority processing condition, it is determined that the first data to be loaded has excess memory allocation authority, and the first data to be loaded is determined as target data.
[0073] Among them, the priority processing conditions include: the first data to be loaded contains multiple sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner; the first data to be loaded is data with a set processing priority; the first data to be loaded corresponds to a processing task with a set priority; or the first data to be loaded corresponds to a user with set priority authority.
[0074] By judging whether the data to be loaded meets the priority processing conditions, it is determined whether the data is given memory excess allocation permission, so that the subsequent loading strategy based on memory excess allocation can achieve a balance between memory capacity and CPU usage during data loading.
[0075] In this step, in order to avoid excessive memory resource usage caused by the target data, after determining the target data that currently needs to be loaded into the memory, it is necessary to determine the target storage capacity required to load the target data into the memory.
[0076] The target storage capacity required to load the target data into the memory can be calculated by taking an image as an example. The storage capacity required to load the current image into the memory can be obtained by directly combining the image resolution with the control size occupied by a single pixel. Taking a GIF as an example, the target storage capacity required to load the target data into the memory can be obtained by detecting the resolution of each frame in the GIF and the total number of frames, and calculating the target storage capacity occupied by loading it into the memory. The calculation formula is:
[0077] The target storage capacity required to load a GIF image into memory = width (px) × height (px) × 4 × number of frames per frame.
[0078] The parameter 4 is because each pixel has 4 channels (RGBA), and each channel is represented by one byte.
[0079] In another optional embodiment, before obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the method further includes:
[0080] Determine the second data to be loaded that currently needs to be loaded into the memory; when it is determined that the second data to be loaded is not the target data, obtain the second target storage capacity required for loading the second data to be loaded into the memory; obtain the remaining calculation storage capacity of the memory, and when it is determined that the remaining calculation storage capacity is greater than the second target storage capacity, refuse to load the second data to be loaded into the memory until the remaining calculation storage capacity is less than or equal to the second target storage capacity.
[0081] Only when the data to be loaded meets the priority processing conditions can it be determined as the target data and granted memory over-allocation rights. If the data to be loaded does not meet the priority processing conditions, it can be determined that the data to be loaded is not the target data, and memory over-allocation rights will not be granted to it. It needs to be loaded according to the existing data loading method.
[0082] That is, when it is determined that the data to be loaded is not the target data, the processing operation of the memory excess allocation authority is not performed, and the data loading process needs to be performed according to another data loading method.
[0083] During the execution of this other data loading method, the remaining calculated storage capacity of the memory is directly compared with the target storage capacity required for the data to be loaded. If the remaining calculated storage capacity is less than the target storage capacity required for the data to be loaded, the data to be loaded is refused to be loaded into the internal storage space, so that the data loading task corresponding to the data to be loaded is still in the task queue. Until it is detected that the remaining calculated storage capacity of the memory is less than or equal to the target storage capacity required for the current data to be loaded, the data loading task is continued to be executed, and the current data to be loaded is loaded into the memory, so that the internal storage space is used correctly and reasonably.
[0084] Step 102, obtain the remaining computational storage capacity of the memory. When it is determined that the remaining computational storage capacity is less than the first target storage capacity, calculate the ratio of the sum of the used computational storage capacity of the memory and the first target storage capacity to the actual total available amount of the memory to obtain a calculation result.
[0085] The remaining computing storage and the used computing storage are calculated based on the set available limit of the memory, and the set available limit is less than the actual total available amount.
[0086] Here, the memory includes: remaining computing storage, used computing storage, actual total available, and set available limit.
[0087] In the design, the remaining computing memory plus the used computing memory equals the set available limit. The remaining computing memory and the used computing memory are calculated in real time during memory usage.
[0088] However, due to discrepancies in actual memory usage, most current free memory calculations are based on the host_statistics provided by the operating system. This free memory statistics are collected from multiple sources, which takes time to collect, and some memory is not included in the statistics. Therefore, the free memory calculation is generally underestimated. This can lead to incorrect memory size estimates.
[0089] Therefore, the calculated remaining computing storage and used computing storage may be less than or equal to the set available limit.
[0090] Moreover, in actual applications, in order to reserve memory usage space for specific data, a portion of the actual total available memory is usually reserved for special use, while a memory availability limit is set for the other portion for normal caching of ordinary data. Therefore, in reality, there is always a portion of the actual total available memory that is unoccupied, and the actual available memory may be far greater than the target storage capacity required to load the target data into the memory.
[0091] In this process, the available limit is designed to be a part of the actual available total, and the remaining part of the actual available total needs to be reserved for other needs.
[0092] Therefore, in this step, when it is calculated that the current remaining computing storage capacity of the internal storage space is less than the target storage capacity required for the target data, in order to avoid the problem of frequent and cyclic reading of data from the disk due to the above reasons and to avoid the problem of failure to respond to more important tasks in a timely manner, the memory usage rules are designed to allow over-allocation, that is, it is allowed to be used beyond the set available limit.
[0093] However, when judging whether to allow the current target data to exceed the memory usage, it is necessary to determine the ratio of the overall memory space occupancy to the actual available total amount when storing the target data based on the remaining computing storage capacity of the current memory, and determine whether to allow the target data to be loaded into the memory based on this ratio value to avoid extreme situations such as memory crashes and avoid a poor user experience.
[0094] Step 103 : Based on the calculation result, when it is determined that the terminal is in the target operating state, the target data is loaded into the memory.
[0095] Based on the ratio in this calculation result, the ratio of the overall memory space occupied to the actual available space can be determined when storing the target data based on the current remaining calculated storage capacity of the memory. Based on this ratio, it is then determined whether the terminal currently allows excess allocation to load the target data into the internal storage space.
[0096] The above processing process in this embodiment takes the target data as a GIF image as an example. Because the GIF image is played at a speed of dozens of frames per second, if each frame or most frames need to read the image from the disk, the CPU usage rate will increase significantly, and the electronic device will become hot, causing the user to actively end the running program or uninstall the App. However, the consequences of using as much memory as possible are not so serious. When the memory is insufficient, the electronic device operating system will first kill the background App to free up memory for the foreground App. If the memory is still not enough, the foreground App will be forcibly killed. Therefore, as long as we do not use too much memory, causing the system to force kill, the consequences of high memory usage are still acceptable.
[0097] We can set a higher upper limit on how much memory can be used to cache GIF images. Instead of using the remaining compute storage based on the available limit to determine how much target data to cache, we can set the upper limit to a safe percentage of the device's physical memory, such as 20%.
[0098] If a mobile phone has 3GB of physical memory, and 20% is used, the maximum memory that can be used to cache GIFs is 600M, which is sufficient for most situations.
[0099] Correspondingly, the terminal is currently in the target operating state. For example, when the target data is stored based on the remaining calculated storage capacity of the current memory, the overall memory space occupancy does not cause too much squeezing of the space required for other normal operations of the terminal, and is within an acceptable range. In this case, it is determined that the terminal is currently in the target allowed state. Or, when the target data is stored based on the remaining calculated storage capacity of the current memory, the CPU usage rate is still within an acceptable level range, in this case, it is determined that the terminal is currently in the target allowed state.
[0100] In this case, if the terminal is currently in the target running state, the target data is loaded into the internal storage space. Otherwise, in order to ensure that the terminal does not experience overload, the target data is not loaded into the internal storage space and is temporarily stored in the disk.
[0101] Specifically, as an optional implementation, based on the calculation result, when it is determined that the terminal is in the target operating state, loading the target data into the memory includes:
[0102] Based on the calculation result, the size relationship between the ratio and the first set threshold is determined; when it is determined that the ratio is less than or equal to the first set threshold, it is determined that the terminal is in the target operating state and the target data is loaded into the memory.
[0103] Correspondingly, when it is determined that the ratio is greater than the first set threshold, it is determined that the terminal is not in the target operating state, and the target data is refused to be loaded into the memory.
[0104] In this process, the memory usage percentage threshold is introduced as a reference factor. Based on the threshold of the actual percentage of the total available memory, it is determined whether the terminal is currently in the target operating state, and the data caching strategy is changed to ensure that as much memory as possible can be used, increase the upper limit of available memory, and reasonably utilize terminal resource configuration to avoid adverse consequences such as overheating of electronic devices.
[0105] As another optional implementation, based on the calculation result, when it is determined that the terminal is in the target operating state, loading the target data into the memory includes:
[0106] Based on the calculation result, determining the magnitude relationship between the ratio and a first set threshold;
[0107] When it is determined that the ratio is greater than the first set threshold, if it is determined that the ratio is less than the second set threshold, detecting the CPU usage of the terminal;
[0108] When the CPU usage is lower than a third set threshold, it is determined that the terminal is in a target operating state, and the target data is loaded into the memory.
[0109] Correspondingly, when the CPU usage is not lower than the third set threshold, it is determined that the terminal is not in the target operating state, and the target data is refused to be loaded into the internal storage space.
[0110] This process introduces the memory usage percentage threshold and CPU usage rate as reference factors. By referring to the usage of these two limited resources, memory and CPU, it is possible to determine whether the terminal is currently in the target operating state, rationally utilize terminal resource configuration, and avoid adverse consequences such as overheating of electronic devices.
[0111] Therefore, the above steps take into account that the existing strategy of determining how much data to cache based on the remaining storage amount calculated based on the available limit set in memory is not reasonable enough, resulting in the need to frequently read data from the disk, causing the CPU usage to rise sharply in a short period of time, bringing about problems such as heating of the electronic device. By changing the cache strategy, the target data is cached in the memory first, in exchange for low CPU usage, and the heating problem of the electronic device that may be caused by loading large target data is solved, and in most cases, there are no other adverse consequences. Even if the memory usage approaches the extreme situation, measures such as pausing data loading or killing the loading program in this case can be set to avoid worse situations, ensure that the operation of the electronic device is orderly and controllable, and by balancing the use of memory and CPU, reduce the frequency of heating of the electronic device, improve the service life of the electronic device, ensure a good user experience, and improve user satisfaction.
[0112] In an embodiment of the present application, by obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the remaining computational storage capacity of the memory is obtained, and when it is determined that the remaining computational storage capacity is less than the first target storage capacity, the ratio of the sum of the used computational storage capacity of the memory and the first target storage capacity to the actual total available amount of the memory is calculated, and finally when it is determined that the terminal is in the target operating state, the target data is loaded into the memory, and by comparing the target storage capacity required for the target data with the remaining computational storage capacity and the actual total available amount of the memory, a cache strategy that exceeds the remaining computational storage capacity of the memory is adopted, so that the target data realizes excess usage of the memory in exchange for low CPU usage, and by balancing the use of memory and CPU, the frequency of heating of electronic devices is reduced, the service life of electronic devices is increased, and the user experience is improved.
[0113] Different implementations of the data loading method are also provided in the examples of this application.
[0114] See also Figure 2 , Figure 2 This is a process of a data loading method provided in an embodiment of the present application Figure 2 .like Figure 2 As shown, a data loading method includes the following steps:
[0115] Step 201: Obtain a first target storage capacity required for loading target data into a memory in a terminal.
[0116] The implementation process of this step is the same as the implementation process of step 101 in the aforementioned embodiment, and will not be repeated here.
[0117] Step 202: Obtain the remaining computational storage capacity of the memory. When it is determined that the remaining computational storage capacity is less than the first target storage capacity, calculate the ratio of the sum of the used computational storage capacity of the memory and the first target storage capacity to the actual total available memory capacity to obtain a calculation result.
[0118] The remaining computing storage and used computing storage are calculated based on the set available limit of the memory, and the set available limit is less than the actual total available amount.
[0119] The implementation process of this step is the same as the implementation process of step 102 in the aforementioned embodiment, and will not be repeated here.
[0120] Step 203 : Based on the calculation result, when it is determined that the terminal is in the target operating state, the target data is loaded into the memory.
[0121] The implementation process of this step is the same as the implementation process of step 103 in the aforementioned embodiment, and will not be repeated here.
[0122] Step 204 : Read the target data from the memory in response to a call request for the target data from the target application in the terminal.
[0123] Step 205: Output the read target data to the target application and delete the target data from the memory.
[0124] This process adopts a specific data loading processing strategy under a specific data object, while not overloading the internal storage space to ensure the normal operation of memory usage.
[0125] In one embodiment, the target data includes a plurality of sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner.
[0126] Correspondingly, the read target data is output to the target application and the target data is deleted from the memory, including:
[0127] According to the data relationship, each sub-data is output to the target application in sequence and in a loop, and when it is detected that the target application ends calling the target data, the target data is deleted from the memory.
[0128] The target data includes multiple sub-data and the sub-data are output in a sequential and cyclical relationship. For example, a GIF image includes multiple image frames, and the image frames need to be output in a sequential and cyclical relationship to achieve a dynamic playback effect of the FIG image.
[0129] When the CPU receives a data operation instruction based on the target application, the CPU responds to the data operation instruction and loads the corresponding target data from the disk into the memory to implement the operation on the target data. For example, the operation is to output the target data to the target application for content display, etc. When the sub-data in the target data have a sequential cyclic output relationship, it is necessary to combine the data call end information feedback from the target application to end the CPU's continuous output of the data to the target application, and delete the target data from the memory in time to realize the timely release of excess memory space and ensure the normal operation of memory usage.
[0130] In an embodiment of the present application, by obtaining the first target storage capacity required for loading target data into the memory in the terminal, the remaining computational storage capacity of the memory is obtained. When it is determined that the remaining computational storage capacity is less than the first target storage capacity, the ratio of the sum of the used computational storage capacity of the memory and the first target storage capacity to the actual total available amount of the memory is calculated. Finally, when it is determined that the terminal is in the target operating state, the target data is loaded into the memory, and when the memory is used up, the excess memory space is released in time. By balancing the use of memory and CPU, the frequency of heating of electronic devices is reduced, the service life of electronic devices is increased, and the user experience is improved.
[0131] See also Figure 3 , Figure 3 This is a structural diagram of a data loading device provided in an embodiment of the present application. For the sake of convenience, only the parts related to the embodiment of the present application are shown.
[0132] The data loading device 300 includes:
[0133] An acquisition module 301 is configured to acquire a first target storage capacity required for loading target data into a memory in a terminal;
[0134] The calculation module 302 is configured to obtain the remaining computing storage capacity of the memory, and when it is determined that the remaining computing storage capacity is less than the first target storage capacity, calculate the ratio of the sum of the used computing storage capacity of the memory and the first target storage capacity to the actual total available capacity of the memory, to obtain a calculation result; wherein the remaining computing storage capacity and the used computing storage capacity are calculated based on a set available limit of the memory, and the set available limit is less than the actual total available capacity;
[0135] The data loading module 303 is configured to load the target data into the memory based on the calculation result when it is determined that the terminal is in the target operating state.
[0136] The device further comprises:
[0137] A data determination module is used to: obtain the first data to be loaded that currently needs to be loaded into the memory; when the first data to be loaded meets the priority processing conditions, determine that the first data to be loaded has memory excess control authority, and determine the first data to be loaded as the target data; wherein, the priority processing conditions include: the first data to be loaded contains multiple sub-data and there is a data relationship between the sub-data that is output in a sequential cycle, the first data to be loaded is data with a set processing priority, or the first data to be loaded corresponds to a user with set priority authority.
[0138] The data determination module is also used to:
[0139] Determining second data to be loaded that currently needs to be loaded into the memory;
[0140] When it is determined that the second data to be loaded is not the target data, obtaining a second target storage capacity required for loading the second data to be loaded into the memory;
[0141] Obtain the remaining computational storage capacity of the memory, and when determining that the remaining computational storage capacity is greater than the second target storage capacity, refuse to load the second data to be loaded into the memory until the remaining computational storage capacity is less than or equal to the second target storage capacity.
[0142] The data loading module 303 is specifically used to:
[0143] Based on the calculation result, determining a magnitude relationship between the ratio and a first set threshold;
[0144] When it is determined that the ratio is less than or equal to a first set threshold, it is determined that the terminal is in the target operating state, and the target data is loaded into the memory.
[0145] The data loading module 303 is specifically used to:
[0146] Based on the calculation result, determining a magnitude relationship between the ratio and a first set threshold;
[0147] When it is determined that the ratio is greater than the first set threshold, if it is determined that the ratio is less than a second set threshold, detecting the CPU usage of the terminal;
[0148] When the CPU usage is lower than a third set threshold, it is determined that the terminal is in the target operating state, and the target data is loaded into the memory.
[0149] The device also includes:
[0150] Remove modules for:
[0151] In response to a call request for the target data from a target application in the terminal, reading the target data from the memory;
[0152] The read target data is output to the target application, and the target data is deleted from the memory.
[0153] Wherein, the target data includes a plurality of sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner, and the deletion module is specifically used to:
[0154] According to the data relationship, each sub-data is cyclically output to the target application in sequence, and when it is detected that the target application ends calling the target data, the target data is deleted from the memory.
[0155] The data loading device provided in the embodiment of the present application can implement each process of the embodiment of the above-mentioned data loading method and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0156] Figure 4 4 is a structural diagram of a computer device provided in an embodiment of the present application. As shown in the figure, the computer device 4 of this embodiment includes: at least one processor 40 ( Figure 4 Only one is shown), a memory 41 and a computer program 42 stored in the memory 41 and executable on the at least one processor 40, wherein the processor 40 implements the steps of any of the above-mentioned method embodiments when executing the computer program 42.
[0157] The computer device 4 can be a desktop computer, a notebook computer, a PDA, a cloud server or other computing devices. The computer device 4 can include, but is not limited to, a processor 40 and a memory 41. Those skilled in the art will understand that Figure 4 It is only an example of the computer device 4 and does not constitute a limitation of the computer device 4. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.
[0158] The processor 40 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0159] The memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. The memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped on the computer device 4. Furthermore, the memory 41 may include both an internal storage unit of the computer device 4 and an external storage device. The memory 41 is used to store the computer program and other programs and data required by the computer device. The memory 41 may also be used to temporarily store data that has been output or is about to be output.
[0160] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0161] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0162] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0163] In the embodiments provided in this application, it should be understood that the disclosed devices / terminals and methods can be implemented in other ways. For example, the device / terminal embodiments described above are merely illustrative. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, 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.
[0164] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0165] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0166] If the integrated module / 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 computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0167] The present application implements all or part of the processes in the above-mentioned embodiment method, and can also be implemented through a computer program product. When the computer program product runs on a terminal, the terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0168] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.
Claims
1. A data loading method, characterized in that: include: Obtaining a first target storage capacity required for loading target data into a memory in the terminal; obtaining a remaining computational storage capacity of the memory, and when determining that the remaining computational storage capacity is less than the first target storage capacity, calculating a ratio of a sum of a used computational storage capacity of the memory and the first target storage capacity to an actual total available amount of the memory, to obtain a calculation result; The remaining computing storage and the used computing storage are calculated based on a set available limit of the memory, and the set available limit is less than the actual total available amount; Based on the calculation result, when it is determined that the terminal is in the target operating state, loading the target data into the memory; The terminal being in the target operating state includes: when the target data is stored based on the remaining calculated storage capacity of the current memory, the overall space occupation of the memory squeezes the space required for other operations of the terminal within a set range, or when the target data is stored based on the remaining calculated storage capacity of the current memory, the CPU usage rate is within a set range; Before obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the method further includes: Obtaining first data to be loaded that currently needs to be loaded into the memory; When the first data to be loaded meets the priority processing condition, determining that the first data to be loaded has memory excess allocation authority, and determining the first data to be loaded as the target data; The priority processing conditions include: the first data to be loaded contains multiple sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner; the first data to be loaded is data with a set processing priority; the first data to be loaded corresponds to a processing task with a set priority; or the first data to be loaded corresponds to a user with a set priority authority; The step of loading the target data into the memory when determining that the terminal is in the target operating state based on the calculation result includes: Based on the calculation result, determining a magnitude relationship between the ratio and a first set threshold; When it is determined that the ratio is greater than the first set threshold, if it is determined that the ratio is less than a second set threshold, detecting the CPU usage of the terminal; When the CPU usage is lower than a third set threshold, it is determined that the terminal is in the target operating state, and the target data is loaded into the memory.
2. The method according to claim 1, characterized in that Before obtaining the first target storage capacity required for loading the target data into the memory in the terminal, the method further includes: Determining second data to be loaded that currently needs to be loaded into the memory; When it is determined that the second data to be loaded is not the target data, obtaining a second target storage capacity required for loading the second data to be loaded into the memory; Obtain the remaining computational storage capacity of the memory, and when determining that the remaining computational storage capacity is greater than the second target storage capacity, refuse to load the second data to be loaded into the memory until the remaining computational storage capacity is less than or equal to the second target storage capacity.
3. The method according to claim 1, characterized in that The step of loading the target data into the memory when determining that the terminal is in the target operating state based on the calculation result includes: Based on the calculation result, determining a magnitude relationship between the ratio and a first set threshold; When it is determined that the ratio is less than or equal to a first set threshold, it is determined that the terminal is in the target operating state, and the target data is loaded into the memory.
4. The method according to claim 1, wherein After the target data is loaded into the memory when it is determined based on the calculation result that the terminal is in the target operating state, the method further includes: In response to a call request for the target data from a target application in the terminal, reading the target data from the memory; The read target data is output to the target application, and the target data is deleted from the memory.
5. The method according to claim 4, characterized in that The target data includes a plurality of sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner, and the outputting the read target data to the target application and deleting the target data from the memory includes: According to the data relationship, each sub-data is cyclically output to the target application in sequence, and when it is detected that the target application ends calling the target data, the target data is deleted from the memory.
6. A data loading device, characterized in that: include: An acquisition module, configured to acquire a first target storage capacity required for loading target data into a memory in a terminal; a calculation module, configured to obtain the remaining computing storage capacity of the memory, and when determining that the remaining computing storage capacity is less than the first target storage capacity, calculate the ratio of the sum of the used computing storage capacity of the memory and the first target storage capacity to the actual total available capacity of the memory, to obtain a calculation result; wherein the remaining computing storage capacity and the used computing storage capacity are calculated based on a set available limit of the memory, and the set available limit is less than the actual total available capacity; a data loading module, configured to load the target data into the memory when it is determined that the terminal is in a target operating state based on the calculation result; The terminal being in the target operating state includes: when the target data is stored based on the remaining calculated storage capacity of the current memory, the overall space occupation of the memory squeezes the space required for other operations of the terminal within a set range, or when the target data is stored based on the remaining calculated storage capacity of the current memory, the CPU usage rate is within a set range; a data determination module configured to obtain first data to be loaded that is currently required to be loaded into the memory; and when the first data to be loaded meets a priority processing condition, determine that the first data to be loaded has memory excess allocation authority, and determine the first data to be loaded as the target data; wherein the priority processing condition includes: the first data to be loaded contains multiple sub-data and there is a data relationship between the sub-data that is output in a sequential and cyclic manner; the first data to be loaded is data with a set processing priority; the first data to be loaded corresponds to a processing task with a set priority; or the first data to be loaded corresponds to a user with a set priority authority; The data loading module is specifically used to determine the size relationship between the ratio and a first set threshold based on the calculation result; when it is determined that the ratio is greater than the first set threshold, if it is determined that the ratio is less than a second set threshold, the CPU usage of the terminal is detected; when the CPU usage is lower than a third set threshold, it is determined that the terminal is in the target operating state and the target data is loaded into the memory.
7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Method, device and computer for automatically cleaning stored data, and storage medium
CN108121783A
Method and device for memory management, readable storage medium, and terminal
CN108932163A