Memory management method and related device, storage medium
By obtaining the expected display frame rate and calculating memory requirements, and adjusting the amount of memory in the memory pool, the problem of discontinuous display on electronic devices was solved, and a stable image rendering effect was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- MEDIATEK SINGAPORE PTE LTD
- Filing Date
- 2024-12-06
- Publication Date
- 2026-06-09
AI Technical Summary
When electronic devices display images on a screen, frame rate variations can cause a mismatch in memory requirements, resulting in discontinuous images.
By obtaining the expected display frame rate, calculating the expected memory requirements, and adjusting the amount of memory in the available memory pool to adapt to changes in the display frame rate, sufficient memory is ensured for data processing.
It effectively prevents discontinuous display and improves the stability and performance of image rendering.
Smart Images

Figure CN122173256A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a memory management method and related devices and storage media. Background Technology
[0002] Electronic devices (such as smartphones and computers) typically use rendering engines to draw images to display different scenes on a display screen.
[0003] Rendering engines require memory space to draw images. Furthermore, the frame rate used by electronic devices to display images on a screen is not constant. As the frame rate increases, more memory is needed to prevent the display from becoming discontinuous due to dropped frames or other reasons.
[0004] Therefore, how to prevent discontinuous display on electronic devices has become an urgent problem to be solved. Summary of the Invention
[0005] This application provides at least one memory management method and related device and storage medium to prevent discontinuous display of electronic devices.
[0006] The first aspect of this application provides a memory management method, including obtaining the expected display frame rate; calculating the expected memory requirement based on the expected display frame rate; and adjusting the amount of memory in the available memory pool based on the expected memory requirement.
[0007] A second aspect of this application provides an electronic device including a memory and a processor coupled to each other, the processor being used to execute program instructions stored in the memory to implement the memory management method of the first aspect described above.
[0008] A third aspect of this application provides a computer-readable storage medium having program instructions stored thereon, which, when executed by a processor, implement the memory management method described in the first aspect above.
[0009] The above solution obtains the expected display frame rate and calculates the expected memory requirements based on it, thereby adjusting the amount of memory in the available memory pool accordingly. Therefore, the amount of memory in the available memory pool can be adjusted based on the expected display frame rate, ensuring that there is sufficient memory to process the data volume corresponding to the expected frame rate during screen rendering, thus preventing display discontinuities.
[0010] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this application. Attached Figure Description
[0011] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.
[0012] Figure 1 This is a flowchart illustrating an embodiment of the memory management method of this application;
[0013] Figure 2 This is a schematic diagram of the framework of an embodiment of the electronic device of this application;
[0014] Figure 3 This is a schematic diagram of a framework of an embodiment of the computer-readable storage medium of this application. Detailed Implementation
[0015] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0016] In the following description, specific details such as particular system architectures, interfaces, and technologies are presented for illustrative purposes rather than for limiting purposes, in order to provide a thorough understanding of this application.
[0017] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, "many" in this document means two or more. Moreover, the term "at least one" in this document means any combination of at least two of any one or more of a plurality of objects. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0018] The first aspect of this application proposes a memory management method that can be applied to electronic devices with display functions, such as mobile phones, tablets, laptops, desktop computers, smartwatches, and other electronic devices.
[0019] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the memory management method of this application; the memory management method includes:
[0020] Step S20: Obtain the expected display frame rate.
[0021] Step S40: Calculate the expected memory requirements based on the expected display frame rate.
[0022] Step S60: Adjust the amount of memory in the available memory pool based on the expected memory requirements.
[0023] The expected display frame rate is a prediction of the future display frame rate. By predicting the future display frame rate and automatically forecasting the expected memory requirements, the amount of memory in the available memory pool can be adjusted in a timely manner to adapt to the display frame rate. For example, when the expected display frame rate increases, the corresponding expected memory requirements will also increase, thereby increasing the amount of memory in the available memory pool in a timely manner. This allows the available memory pool to cope with the larger amount of data brought about by the expected display frame rate, thus preventing the problem of discontinuous display.
[0024] The available memory pool can be the memory pool used by foreground applications. A foreground application is an application currently displaying its image on the screen. There can be one, two, or more foreground applications. For example, in a split-screen scenario, the foreground applications could be all applications currently displaying their images on the screen. For scenarios with multiple foreground applications, the expected memory requirements of each foreground application can be calculated based on their expected frame rates, and the amount of memory in the available memory pool corresponding to each foreground application can then be adjusted.
[0025] It should be understood that in this article, memory can refer to cache, buffer, or memory.
[0026] In some embodiments, the expected display frame rate can be actively set by the user or the foreground application. In this case, the expected memory requirement can be calculated directly from the expected display frame rate actively set by the user or the foreground application, and the amount of memory in the available memory pool can then be adjusted.
[0027] In some embodiments, if the user or the foreground application does not actively set the expected display frame rate, the expected display frame rate is calculated and dynamically updated.
[0028] For example, if the expected display frame rate is not actively set, the system display frame rate can be used as the expected display frame rate. The system display frame rate refers to the display frame rate set by the system. The system can adaptively set the display frame rate according to the type of the currently displayed screen. For example, if the current displayed screen type is a static image, the system display frame rate can be adaptively set to a lower frame rate, such as 60Hz; if the current displayed screen type is a dynamic image, the system display frame rate can be adaptively set to a higher frame rate, such as 120Hz; the system can also adaptively set the display frame rate according to the current status of the electronic device (such as remaining battery power), and can also force the system display frame rate to be fixed at a certain frame rate, etc., which are not limited in this application.
[0029] For example, if the expected display frame rate is not actively set, the current actual display frame rate can be used as the expected display frame rate. The actual display frame rate can be the average frame rate, median frame rate, etc., corresponding to the most recent preset time period or the most recent preset number of frames, or the display frame rate at the current moment can be directly taken as the actual display frame rate.
[0030] For example, if the expected display frame rate is not actively set, it can be selected from the current actual display frame rate and the system display frame rate as the expected display frame rate. For example, the smaller value between the actual display frame rate and the system display frame rate can be selected as the expected display frame rate.
[0031] In some embodiments, obtaining the expected display frame rate includes:
[0032] Step S210: Obtain the system display frame rate and calculate the actual display frame rate; wherein, the system display frame rate is the display frame rate set by the system.
[0033] Step S220: Use the smaller value between the system display frame rate and the actual display frame rate as the expected display frame rate.
[0034] The system display frame rate and the actual display frame rate can be referred to the description in the foregoing embodiments, and will not be repeated here.
[0035] In some embodiments, if the system display frame rate is updated during the calculation of the actual display frame rate, the calculation of the actual display frame rate is stopped, and the updated system display frame rate is used as the expected display frame rate.
[0036] The system's frame rate has been updated, likely because the system has comprehensively evaluated factors such as the current electronic device status and the type of screen being displayed, determining the optimal frame rate. Subsequent displays will then adhere to this optimal frame rate. Therefore, it can be directly used as the expected frame rate to calculate anticipated memory requirements and adjust the amount of memory in the available memory pool. This reduces the computational load required to calculate the expected frame rate, thus saving memory.
[0037] In some embodiments, calculating the actual display frame rate in step S210 includes:
[0038] Step S211: Obtain the rendering request initiation time of the preset number of frames closest to the current time.
[0039] Step S212: Calculate the time interval between each two adjacent frames in the preset number of frame images for initiating a drawing request.
[0040] Step S213: Obtain the central tendency representation value of the time interval between each two adjacent frames for initiating a drawing request.
[0041] Step S214: Calculate the actual display frame rate based on the central tendency characterization value.
[0042] When performing step S211, the drawing request initiation time of the nearest consecutive preset number of frame images is obtained. For example, a sliding window can be set to store the drawing request initiation times of the preset number of frame images; and the sliding window is always used to store the drawing request initiation times of the nearest preset number of frame images. Assuming the preset number is N (N can be 3, 4, 5, etc., and this application does not limit this), the sliding window is used to store the drawing request initiation times Q1, Q2, Q3...QN of the N nearest frame images, where QN is the drawing request initiation time of the frame closest to the current time; when the (N+1)th frame arrives, the content stored in the sliding window becomes: Q2, Q3, Q4...QN, Q(N+1). In other embodiments, step S211 can also be: obtaining the drawing request initiation times corresponding to several frames within the nearest preset time period. For example, the drawing request initiation times corresponding to all frames within the last 2 seconds can be obtained.
[0043] As is understandable, the draw request initiation time refers to the moment when a draw request is initiated for a frame of image. By calculating the draw request initiation time interval between two adjacent frames, the refresh interval between those two frames can be obtained, and thus the display frame rate can be determined.
[0044] In step S213, for example, after obtaining the drawing request initiation times Q1, Q2, Q3...QN of N frames, the drawing request initiation time interval between each two adjacent frames can be represented as QN-Q(N-1). The central tendency representation value of the drawing request initiation time interval between each two adjacent frames can be the average time interval calculated using the drawing request initiation time interval QN-Q(N-1) between each two adjacent frames, or it can be the median or midpoint of the drawing request initiation time interval between each two adjacent frames, etc. This application does not limit the calculation method of the central tendency representation value.
[0045] In step S214, the central tendency frame rate can first be calculated based on the central tendency representation value. Since the central tendency representation value is the central tendency representation value of the refresh interval time, it can be converted into the form of frame rate first. After obtaining the central tendency frame rate, it can be compared with the system display frame rate, and one of them can be used as the actual display frame rate, for example, the smaller value can be used as the actual display frame rate.
[0046] In some embodiments, the memory management method further includes:
[0047] Step S215: In response to the time interval between two adjacent frames exceeding the first preset time interval, discard the time interval for initiating a preset number of frame images, and re-execute the time interval for initiating a preset number of frame images closest to the current time, and the subsequent operations.
[0048] The first preset time interval can be associated with the system refresh interval, for example, it can be 2 times, 3 times, etc., of the system refresh interval. This application does not limit the specific calculation relationship between the first preset time interval and the system refresh interval; the first preset time interval can also be manually set by the user. The system refresh interval corresponds to the system display frame rate and refers to the refresh time interval between two frames of images set by the system.
[0049] When the time interval between rendering requests for two adjacent frames exceeds a first preset time interval, there is reason to suspect a change in the current rendering environment. Therefore, to avoid interference from older content in the sliding window to newer content, it is possible to select all content in the sliding window, i.e., discard the rendering request initiation times of a preset number of frames and re-record them. This improves the accuracy of the actual display frame rate calculation, thereby improving the accuracy of the expected display frame rate. Consequently, it allows the adjustment of the available memory pool to more closely match the expected memory requirements, further preventing discontinuous display.
[0050] In some embodiments, the memory management method further includes:
[0051] Step S216: In response to the drawing request initiation time interval between two adjacent frames being less than the second preset time interval, discard the drawing request initiation time of the corresponding frame, and based on the drawing request initiation time of the remaining frames, perform the calculation of the drawing request initiation time interval between each two adjacent frames in a preset number of frame images, and the subsequent operations.
[0052] The second preset time interval can be associated with the system refresh interval, for example, it can be 0.5 times, 0.7 times or other times of the system refresh interval. This application does not limit the specific calculation relationship between the second preset time interval and the system refresh interval; the second preset time interval can also be manually set by the user.
[0053] When the time interval between drawing request initiation for two adjacent frames is less than a second preset time interval, it may be because the corresponding frame is invalid, etc. In this case, only the drawing request initiation time of the corresponding frame needs to be deleted, instead of deleting the drawing request initiation times of all frames. It can be understood that the "corresponding frame" can be the frame preceding or following one of the two adjacent frames where the drawing request initiation time interval is less than the second preset time interval, or it can be both the preceding and following frames. By deleting the drawing request initiation times of the corresponding frames, the interference of extreme values on the calculation results can be prevented, improving the accuracy of the actual display frame rate calculation, thereby improving the accuracy of the expected display frame rate. This, in turn, makes the adjustment of the available memory pool more closely match the expected memory requirements, further preventing the occurrence of discontinuous display.
[0054] It is understood that the above steps S215 and S216 are not necessarily executed after steps S211 to S214. They can also be executed between steps S211 and S214. That is, when the time interval between the drawing request initiation between two adjacent frames meets the conditions in step S215 or step S216, the process can jump to step S215 or step S216.
[0055] In some embodiments, the memory management method further includes:
[0056] Step S30: Determine the maximum available memory.
[0057] The maximum available memory is used to limit the unlimited expansion of the available memory pool. In some embodiments, the amount of memory in the adjusted available memory pool does not exceed the maximum available memory. The maximum available memory can be the maximum available memory for the foreground application; if there is more than one foreground application, and each foreground application corresponds to a different available memory pool, the maximum available memory for each foreground application can be determined separately; alternatively, multiple foreground applications can be allocated to the same available memory pool, and the maximum available memory for each of these foreground applications is the maximum available memory for that same available memory pool. Therefore, by setting a maximum available memory, the unlimited expansion of the available memory pool can be prevented from crowding out the available memory of other processes.
[0058] In some embodiments, the maximum available memory can be calculated based on parameters such as system memory size (represented by system_memory), screen resolution (represented by display_resolution), maximum supported color depth (represented by max_buffer_depth), and maximum number of running programs (represented by max_app_support). Here, system memory size refers to the current system's DRAM memory size; maximum supported color depth refers to the maximum color depth of the buffer formats supported by the system; for example, if the current system supports a maximum of RGBA8888, then the maximum supported color depth is 32; and the maximum number of running programs refers to the maximum number of foreground and background applications that the system can support running simultaneously. Background application killing will not occur when the sum of the number of foreground and background applications running simultaneously does not exceed the maximum number of running programs.
[0059] For example, the maximum available memory can be calculated using the following formula: MAX = groundup(system_memory / 2.5 / (display_resolution / 1024 / 1024 / 8) / max_buffer_depth / max_app_support) – 1. Here, MAX represents the maximum available memory, and groundup refers to rounding up. Taking a system memory size of 8192MB, a screen resolution of 1080*2400, a maximum supported color depth of 32, and a maximum number of running programs of 18 as an example, then MAX is groundup(8192 / 2.5 / (1080*2400 / 1024 / 1024 / 8) / 32 / 18) – 1 = 18, meaning the final calculated maximum available memory is 18.
[0060] In some embodiments, adjusting the amount of memory in the available memory pool based on expected memory requirements includes:
[0061] Step S610: In response to the anticipated increase in memory demand, add memory to the available memory pool.
[0062] By adding memory to the available memory pool when anticipated memory demand increases, the available memory pool can be replenished in a timely manner to cope with larger data volumes, thereby improving data processing performance and preventing display discontinuities.
[0063] In some embodiments, adjusting the amount of memory in the available memory pool based on expected memory requirements further includes:
[0064] Step S620: In response to the expected decrease in memory demand, remove memory from the available memory pool.
[0065] By removing memory from the available memory pool when expected memory requirements decrease, memory that is no longer needed can be released in a timely manner, thus avoiding the problem of excessive memory consumption when memory requirements for screen rendering are low, which could affect the operation of other programs.
[0066] In some embodiments, removing memory from the available memory pool in response to a anticipated decrease in memory demand includes:
[0067] Step S621: In response to the expected decrease in memory demand, remove memory that was added to the available memory pool later from the available memory pool according to the order in which it was added.
[0068] In other embodiments, memory in the available memory pool can also be deleted randomly. Compared to embodiments with random deletion, this embodiment improves memory management efficiency by deleting memory from the available memory pool in the order it was added to the pool.
[0069] Identifiers, such as index values, can be assigned to each memory segment according to the order in which they are added to the available memory pool. For example, the index value of the first memory segment added to the available memory pool could be 1, the index value of the second memory segment could be 2, and so on. When the expected memory demand decreases, the memory segments in the available memory pool are sorted according to their index values, and memory segments with larger index values are removed from the available memory pool first. Specifically, the memory segments that need to be removed can be removed from the available memory pool only when they become available.
[0070] In some embodiments, the memory management method further includes configuring memory information for memory in the available memory pool. Memory information includes, but is not limited to: memory request reason, memory state, process ID, inter-process communication handle (BinderHandle), memory index, frame index, etc.
[0071] The reason for memory allocation indicates why the memory is added to the available memory pool. This includes default requests, automatic requests, temporary automatic requests, and manual requests. A default request means that the memory is allocated to the available memory pool by default when it is created; therefore, initially, all memory allocations in the available memory pool are for default reasons. An automatic request means that the memory is added to the available memory pool due to an increase in expected memory demand. A temporary automatic request means that the memory is temporarily added to the available memory pool when the memory access duration exceeds a preset duration; temporary automatic requests will be further described in subsequent embodiments. A manual request means that the memory is manually added to the available memory pool; manual requests will also be further described in subsequent embodiments.
[0072] Memory state indicates the current status of a memory block, including free, queued, acquired, and released. Initially, the memory is free.
[0073] Process ID, which corresponds to the ID of the process that uses memory for screen rendering.
[0074] The inter-process communication handle (Binder Handle) is used for cross-thread communication and is initially set to the current binder object.
[0075] Memory indexes can be used to indicate the order in which memory is added to the available memory pool. For example, the index value of the first memory added to the available memory pool can be 1, the index value of the first memory added to the available memory pool can be 2, and so on. For details, please refer to the relevant description above.
[0076] The frame index is empty when it is not actually used in memory.
[0077] In some embodiments, when adjusting the amount of memory in the available memory pool according to expected memory requirements, the memory is also marked with the corresponding memory request reason; for example, if the expected memory requirements increase and new memory is added to the available memory pool, the memory request reason for the corresponding memory is marked as automatic request.
[0078] In some embodiments, in response to a decrease in expected memory demand, memory is removed from the available memory pool. This can be done by removing memory from the available memory pool whose memory request reason is automatic request. For example, several memory pools with automatic request reason and the largest memory index can be removed from the available memory pool when their memory status is idle.
[0079] In some embodiments, the method further includes:
[0080] Step S51: In response to the expected display frame rate update, recalculate the new expected memory requirement and record the expected memory requirement corresponding to the expected display frame rate before the update as the old expected memory requirement.
[0081] Step S52: Calculate the difference between the new expected memory demand and the old expected memory demand.
[0082] In this embodiment, by calculating the difference between the new and old expected memory requirements, the amount of memory in the available memory pool can be adaptively adjusted based on the difference, so that the amount of memory in the available memory pool more accurately matches the new expected memory requirements, and better prevents the occurrence of discontinuous display.
[0083] In some embodiments, adding memory to the available memory pool in response to an increase in expected memory demand includes: adding memory to the available memory pool corresponding to the difference in demand in response to an increase in new expected memory demand relative to old expected memory demand.
[0084] In this embodiment, by calculating the difference between the new and old expected memory requirements, the amount of memory in the available memory pool can be adaptively increased based on the difference, so that the amount of memory in the available memory pool more accurately matches the new expected memory requirements, and better prevents the occurrence of discontinuous display.
[0085] In some embodiments, removing memory from the available memory pool in response to a anticipated decrease in memory demand includes:
[0086] In response to a decrease in expected memory demand relative to the old expected memory demand, memory corresponding to the difference in demand is removed from the available memory pool.
[0087] In this embodiment, by calculating the difference between the new and old expected memory requirements, the amount of memory in the available memory pool can be adaptively reduced based on the difference. This ensures that the available memory pool does not waste memory, and the amount of memory in the available memory pool can more accurately match the new expected memory requirements, thus better preventing the occurrence of discontinuous display.
[0088] In some embodiments, the method further includes:
[0089] Step S70: Determine the default expected memory requirements.
[0090] The default expected memory requirement (labeled DUB) can be calculated from the default expected display frame rate, the system display frame rate, and the default memory requirement (labeled DB). The default expected display frame rate can be set by the user or the foreground application.
[0091] When the user or foreground application has not set a default expected display frame rate, or when the set default expected display frame rate is greater than the system display frame rate, the system display frame rate can be used as the default expected display frame rate.
[0092] The default memory requirement (DB) can be calculated using the following formula: DB = 3 + max(0, groundup((sf_duration + app_duration) / display_refresh_ms) - 2). Here, max() represents the operation of taking the maximum value; sf_duration refers to the expected execution time per frame of the system's SF+HWC (in milliseconds); app_duration is the expected execution time per frame of the system's APP; and display_refresh_ms is the current refresh interval set by the system.
[0093] The default expected memory requirement (DUB) can be calculated using the following formula: DUB = groundup(DB / display_fps * default_user_fps). Where display_fps is the system display frame rate, and default_user_fps is the default expected display frame rate.
[0094] In some embodiments, adding memory to the available memory pool in response to an increase in expected memory demand includes: adding memory to the available memory pool corresponding to the difference in demand in response to an increase in new expected memory demand relative to the default expected memory demand.
[0095] Removing memory from the available memory pool in response to a decrease in expected memory demand includes: removing memory from the available memory pool corresponding to the difference in demand in response to a decrease in new expected memory demand relative to the default expected memory demand.
[0096] Understandably, when the new expected memory requirement is the first expected memory requirement calculated based on the memory management method, there is no "old expected memory requirement" to refer to in order to determine whether to increase or decrease memory. Therefore, the new expected memory requirement can be compared with the default expected memory requirement to determine whether to add memory from the available memory pool or to delete memory from the available memory pool.
[0097] In this embodiment, by calculating the demand difference, the amount of memory in the available memory pool can be adaptively reduced based on this difference. This prevents wasted memory and ensures that the available memory pool more accurately reflects the new expected memory requirements, thus better preventing display discontinuities. Conversely, by calculating the demand difference, the amount of memory in the available memory pool can be adaptively increased based on this difference, further ensuring that the available memory pool more accurately reflects the new expected memory requirements and better preventing display discontinuities.
[0098] In some embodiments, the method further includes:
[0099] Step S81: In response to the memory call duration in the available memory pool exceeding the preset call duration, and all memory in the available memory pool being occupied, a preset amount of emergency memory is added to the available memory pool.
[0100] The memory access duration in the available memory pool refers to the time it takes for a new frame of image to be processed (i.e., waiting to be drawn). If no idle or released memory is available to process the data of that new frame, the new frame must wait for memory to be released before it can be processed. A longer access duration indicates higher memory usage. In this case, a preset amount of emergency memory can be temporarily allocated to the available memory pool.
[0101] The preset call duration can be set according to actual needs. For example, it can be set to be related to the system refresh interval, such as 0.2 times or 0.3 times the system refresh interval. This application does not impose any restrictions. The preset number of temporary additional emergency memory requests can also be set according to actual needs, such as 1 block or 2 blocks.
[0102] In some embodiments, the memory information of emergency memory temporarily requested to be added to the available memory pool will be filled with the memory request reason, and the corresponding memory request reason is temporary automatic request.
[0103] In some embodiments, the method further includes:
[0104] Step S81: In response to the fact that the available memory for a preset number of frames is greater than a preset free threshold, the emergency memory is deleted from the available memory pool when the emergency memory is not occupied.
[0105] Emergency memory is not occupied, meaning that the memory status of emergency memory is either free or released.
[0106] The preset number of frames can be, for example, 3 consecutive frames, 2 consecutive frames, 4 consecutive frames, or 1 frame; this application does not impose any restrictions. The preset idle threshold can be 1, 2, 3, etc.
[0107] In some embodiments, if the amount of memory in the adjusted available memory pool is greater than the maximum available memory, then even if the call duration of memory in the available memory pool exceeds the preset call duration and all memory in the available memory pool is occupied, no emergency memory will be added to the available memory pool.
[0108] In some embodiments, the method further includes:
[0109] Step S91: In response to the memory increment instruction, add memory to the available memory pool.
[0110] A memory increment instruction is a memory increment instruction actively issued by a user or foreground application, indicating that the user or foreground application wants to increase the size of the available memory pool.
[0111] In some embodiments, memory added to the available memory pool in response to a memory increment instruction can be marked as a manual request.
[0112] In some embodiments, the method further includes:
[0113] Step S92: In response to the memory release instruction, remove the memory from the available memory pool.
[0114] A memory release command is a memory release command initiated by the user or a foreground application, indicating that the user or foreground application wants to reduce the size of the available memory pool.
[0115] In some embodiments, the deletion of memory from the available memory pool in response to a memory release instruction can be performed when the memory requested for a reason that was manually requested is in a free state.
[0116] In some embodiments, the method further includes:
[0117] Step S100: Obtain the default memory requirement, maximum available memory, and system display frame rate; wherein, the system display frame rate is the display frame rate set by the system.
[0118] The calculation methods for default memory requirements and maximum available memory can be found in the aforementioned embodiments and will not be repeated here.
[0119] The expected memory requirements, calculated based on the expected display frame rate, include:
[0120] Step S41: Obtain the expected memory requirement coefficient based on the ratio of the expected display frame rate to the system display frame rate.
[0121] Step S42: Multiply the default memory requirement by the expected memory requirement coefficient to obtain the candidate value of the expected memory requirement;
[0122] Step S43: Select the smaller value from the maximum available memory and the candidate values of expected memory requirement as the expected memory requirement.
[0123] Specifically, steps S41 to S43 can be represented by the following formulas:
[0124] user_buffer_size = min(MAX, groundup((default-buffer-size) / display_fps*user_fps)). Here, user_buffer_size is the expected memory requirement, default-buffer-size is the default memory requirement, user_fps is the expected display frame rate, and min() represents the operation to find the minimum value.
[0125] In some embodiments, the method further includes: asynchronously pre-allocating memory and establishing a memory mapping according to default memory requirements.
[0126] For example, during the initialization phase, a portion of memory needs to be allocated for upcoming rendering operations. Therefore, memory can be pre-allocated according to the default memory requirements. Mapping refers to importing memory objects into the cache in a mapped form for later use.
[0127] In some embodiments, after the mapping is established, memory information can be configured for each memory location, and all memory mappings can be placed in a queue for subsequent decision-making. Further description of the memory information can be found in the foregoing embodiments and will not be repeated here.
[0128] In some embodiments, memory pre-allocated according to default memory requirements will not be deleted or added during subsequent adjustments to the amount of memory in the available memory pool based on the expected display frame rate.
[0129] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0130] Please see Figure 2 , Figure 2 This is a schematic diagram of a framework of an embodiment of the electronic device of this application. The electronic device 20 includes a memory 21 and a processor 22 coupled to each other. The processor 22 is used to execute program instructions stored in the memory 21 to implement the steps in any of the above-described memory management method embodiments. In a specific implementation scenario, the electronic device 20 may include, but is not limited to, a microcomputer or a server. In addition, the electronic device 20 may also include mobile devices such as laptops and tablets, which are not limited here.
[0131] Specifically, processor 22 controls itself and memory 21 to implement the steps in any of the memory management method embodiments described above. Processor 22 may also be referred to as a CPU (Central Processing Unit). Processor 22 may be an integrated circuit chip with signal processing capabilities. Processor 22 may also be a general-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor may be a microprocessor or any conventional processor. Furthermore, processor 22 may be implemented using integrated circuit chips.
[0132] Electronic devices may also have a display (not shown) for displaying images.
[0133] The above solution obtains the expected display frame rate and calculates the expected memory requirements based on it, thereby adjusting the amount of memory in the available memory pool accordingly. Therefore, the amount of memory in the available memory pool can be adjusted based on the expected display frame rate, ensuring that there is sufficient memory to process the data volume corresponding to the expected frame rate during screen rendering, thus preventing display discontinuities.
[0134] Please see Figure 3 , Figure 3 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present application. The computer-readable storage medium 30 stores program instructions 301 that can be executed by a processor. The program instructions 301 are used to implement the steps in any of the above-described memory management method embodiments.
[0135] The above solution obtains the expected display frame rate and calculates the expected memory requirements based on it, thereby adjusting the amount of memory in the available memory pool accordingly. Therefore, the amount of memory in the available memory pool can be adjusted based on the expected display frame rate, ensuring that there is sufficient memory to process the data volume corresponding to the expected frame rate during screen rendering, thus preventing display discontinuities.
[0136] In some embodiments, the functions or modules of the apparatus provided in this disclosure can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0137] The description of the various embodiments above tends to emphasize the differences between the various embodiments. The similarities or similarities between them can be referred to, and for the sake of brevity, they will not be repeated here.
[0138] In the several embodiments provided in this application, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus implementations described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0139] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0140] If the integrated unit is implemented as 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 technical solution of this application, in essence, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0141] If the technical solution of this application involves personal information, the product using this technical solution has clearly informed the user of the personal information processing rules and obtained the user's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using this technical solution has obtained the user's separate consent before processing the sensitive personal information, and also meets the requirement of "express consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set up to inform users that they have entered the scope of personal information collection and that personal information will be collected. If an individual voluntarily enters the collection scope, it is deemed that they have agreed to the collection of their personal information; or on the personal information processing device, with clear signs / information informing users of the personal information processing rules, authorization is obtained from the individual through pop-up information or by asking the individual to upload their personal information; wherein, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the types of personal information processed.
Claims
1. A memory management method, characterized in that, include: Get the expected display frame rate; The expected memory requirement is calculated based on the expected display frame rate. Based on the expected memory requirements, adjust the amount of memory in the available memory pool.
2. The memory management method according to claim 1, characterized in that, The process of obtaining the expected display frame rate includes: Obtain the system display frame rate and calculate the actual display frame rate; wherein, the system display frame rate is the display frame rate set by the system; The smaller of the system display frame rate and the actual display frame rate is taken as the expected display frame rate.
3. The memory management method according to claim 2, characterized in that, The method further includes: If the system display frame rate is updated during the calculation of the actual display frame rate, the calculation of the actual display frame rate is stopped, and the updated system display frame rate is used as the expected display frame rate.
4. The memory management method according to claim 2, characterized in that, The calculation of the actual display frame rate includes: Get the time when the drawing request for the nearest preset number of frames is initiated; Calculate the time interval between each two adjacent frames in the preset number of frame images; Obtain the central tendency representation value of the time interval between each two adjacent frames for initiating a rendering request; The actual display frame rate is calculated based on the central tendency characterization value.
5. The memory management method according to claim 4, characterized in that, The method further includes: In response to the time interval between the drawing request initiation of two adjacent frames exceeding a first preset time interval, the drawing request initiation time of the acquired preset number of frame images is discarded, and the drawing request initiation time of acquiring the preset number of frame images closest to the current time is re-executed, as well as the subsequent operations; And / or, In response to the fact that the time interval between the drawing request initiation of two adjacent frames is less than a second preset time interval, the drawing request initiation time of the corresponding frame is discarded, and based on the drawing request initiation time of the remaining frames, the calculation of the time interval between the drawing request initiation of each pair of adjacent frames in the preset number of frame images, and subsequent operations are performed.
6. The memory management method according to claim 1, characterized in that, The method further includes: determining the maximum available memory; Wherein, the amount of memory in the adjusted available memory pool is no greater than the maximum available memory.
7. The memory management method according to claim 1 or 6, characterized in that, Adjusting the amount of memory in the available memory pool based on the expected memory requirements includes: In response to the anticipated increase in memory demand, additional memory is added to the available memory pool; In response to the expected decrease in memory demand, the memory is removed from the available memory pool.
8. The memory management method according to claim 7, characterized in that, The step of removing memory from the available memory pool in response to the expected decrease in memory demand includes: In response to the expected decrease in memory demand, memory that was added to the available memory pool later is removed from the available memory pool in the order it was added.
9. The memory management method according to claim 7, characterized in that, The method further includes: In response to the update of the expected display frame rate, the new expected memory requirement is recalculated, and the expected memory requirement corresponding to the expected display frame rate before the update is recorded as the old expected memory requirement. Calculate the difference between the new expected memory requirement and the old expected memory requirement; The step of adding memory to the available memory pool in response to the anticipated increase in memory demand includes: In response to the increase in the new expected memory demand relative to the old expected memory demand, additional memory corresponding to the difference in demand is added to the available memory pool; The step of removing memory from the available memory pool in response to the expected decrease in memory demand includes... In response to a decrease in the expected memory requirement relative to the old expected memory requirement, memory corresponding to the difference in requirement is removed from the available memory pool.
10. The memory management method according to claim 9, characterized in that, The method further includes: Determine the default expected memory requirements; The step of adding memory to the available memory pool in response to the anticipated increase in memory demand includes: In response to the increase in the new expected memory requirement relative to the default expected memory requirement, additional memory corresponding to the difference in requirement is added to the available memory pool; The step of removing memory from the available memory pool in response to the expected decrease in memory demand includes... In response to the decrease in the new expected memory requirement relative to the default expected memory requirement, memory corresponding to the difference in requirement is removed from the available memory pool.
11. The memory management method according to claim 1 or 6, characterized in that, The method further includes: If the memory access time in the available memory pool exceeds the preset access time, and all memory in the available memory pool is occupied, then a preset amount of emergency memory is added to the available memory pool.
12. The memory management method according to claim 11, characterized in that, The method further includes: In response to a preset number of frames of images having more available memory than a preset free threshold, the emergency memory is deleted from the available memory pool when it is not occupied.
13. The memory management method according to claim 1 or 6, characterized in that, The method further includes: In response to a memory increment command, add new memory to the available memory pool; In response to a memory release command, the memory is removed from the available memory pool.
14. The memory management method according to claim 1, characterized in that, The method further includes: Obtain the default memory requirements, maximum available memory, and system display frame rate; wherein, the system display frame rate is the display frame rate set by the system. The step of calculating the expected memory requirement based on the expected display frame rate includes... The expected memory requirement coefficient is obtained by dividing the expected display frame rate by the system display frame rate; Multiply the default memory requirement by the expected memory requirement coefficient to obtain candidate values for the expected memory requirement. The smaller value between the maximum available memory and the candidate values of the expected memory requirement is selected as the expected memory requirement.
15. An electronic device, characterized in that, The device includes a memory and a processor coupled to each other, the processor being configured to execute program instructions stored in the memory to implement the memory management method according to any one of claims 1 to 14.
16. A computer-readable storage medium having program instructions stored thereon, characterized in that, When the program instructions are executed by the processor, they implement the memory management method according to any one of claims 1 to 14.