Game resource caching method and device
Patent Information
- Application Number
- CN202311728774.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-14
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2043-12-14
AI Technical Summary
[0008]本发明的目的在于针对现有技术的不足之处,提供一种游戏资源缓存方法及装置,以解决现有技术中的缓存实现方案对降低游戏卡顿、发热以及内存碎片,提升游戏性能效果的作用有限的问题
[0037] The beneficial effects of the present invention are as follows: The game resource caching method and apparatus of the present invention obtain the resource loading times and memory usage information of game resources in the game; calculate the caching benefits of game resources based on the resource loading times and memory usage information; and add or unload game resources based on the caching benefits. By using the caching mechanism, the problems of game lag, overheating and memory fragmentation are reduced, thereby improving game performance.
Smart Images

Figure CN117717787B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of game development technology, and more specifically to a game resource caching method and apparatus. Background Technology
[0002] Game resource caching primarily aims to improve game performance and loading speed. In game development, game resources are typically packaged into binary files, which are then loaded and released at runtime as needed. Currently, existing caching implementations are fragmented and lack a solution better suited to game development practices.
[0003] The current mainstream caching methods on the market mainly suffer from the following problems:
[0004] The cache management strategy is rather crude, simply setting a cache limit and directly clearing old resources once the limit is exceeded. It does not truly link to memory usage, so when memory usage is high, caching will continue, causing additional performance issues.
[0005] During caching, the cost-effectiveness of resources cannot be identified, causing resources to be unloaded prematurely. This results in resources that should not be cached continuously occupying memory, while high-cost-effective resources are frequently unloaded and loaded.
[0006] The cache type is singular, and there is no unified framework for abstraction. It is mostly implemented based on a single type, which reduces the code's generality and maintainability. For example, extending the cache to other types is mostly quite complex.
[0007] Existing caching solutions have limited effectiveness in reducing game stuttering, overheating, and memory fragmentation, and in improving game performance. Summary of the Invention
[0008] The purpose of this invention is to address the shortcomings of existing technologies by providing a game resource caching method and apparatus, thereby solving the problem that existing caching solutions have limited effectiveness in reducing game lag, overheating, and memory fragmentation, and improving game performance.
[0009] In a first aspect, the present invention provides a game resource caching method, comprising:
[0010] Obtain information on the number of times game resources are loaded and their memory usage in the game;
[0011] The cache revenue of the game resources is calculated according to the formula: Cache Revenue = Resource Loading Times * Weight + Memory Usage Information * Weight.
[0012] Game resources are added or uninstalled based on the cached revenue.
[0013] Furthermore, adding and unloading game resources based on the aforementioned cache revenue includes:
[0014] Sort the caching benefits of different game resources from highest to lowest;
[0015] Optimize the cache hit rate of different game resources based on the sorting results.
[0016] Furthermore, the method also includes:
[0017] Count the number of times different game resources are loaded;
[0018] The weights in the formula are adjusted based on the number of times the resource is loaded, with higher weights assigned to game resources that are loaded more times.
[0019] Furthermore, the method also includes:
[0020] Once game resources are loaded, the lifecycle of resources is automatically managed based on the cached revenue, automatically unloading unused resources and reclaiming resources that are no longer needed.
[0021] Furthermore, the method also includes:
[0022] It provides developers with a custom caching strategy, which sorts and manages game resources based on their usage frequency, size, and priority.
[0023] Secondly, the present invention provides a game resource caching device, comprising:
[0024] The acquisition unit is used to acquire information on the number of times game resources are loaded and the memory usage of game resources.
[0025] The calculation unit is used to calculate the cache revenue of the game resources according to the formula: Cache revenue = Resource loading times * weight + Memory usage information * weight;
[0026] The add / unload unit is used to add or unload game resources based on the cached revenue.
[0027] Furthermore, the loading / unloading unit includes:
[0028] The sorting unit is used to sort the caching benefits of different game resources from high to low.
[0029] The optimization unit is used to optimize the cache hit rate of different game resources according to the sorting results.
[0030] Furthermore, the device also includes:
[0031] The statistics unit is used to count the number of times different game resources are loaded.
[0032] The adjustment unit is used to adjust the weights in the formula according to the number of times the resource is loaded, and to assign higher weights to game resources with higher resource loading times.
[0033] Furthermore, the device also includes:
[0034] The management unit is used to automatically manage the lifecycle of game resources based on the cache revenue after the game resources are loaded, and to automatically uninstall unused resources and recycle resources that are no longer needed.
[0035] Furthermore, the device also includes:
[0036] The custom unit is used to provide developers with custom caching strategies, which are sorted and managed according to the usage frequency, size, and priority of game resources.
[0037] The beneficial effects of the present invention are as follows: The game resource caching method and apparatus of the present invention obtain the resource loading times and memory usage information of game resources in the game; calculate the caching benefits of game resources based on the resource loading times and memory usage information; and add or unload game resources based on the caching benefits. By using the caching mechanism, the problems of game lag, overheating and memory fragmentation are reduced, thereby improving game performance.
[0038] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0039] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings:
[0040] Figure 1 This is a flowchart of the game resource caching method of the present invention;
[0041] Figure 2 This is a schematic diagram of the game resource caching device of the present invention. Detailed Implementation
[0042] The following non-limiting embodiments are intended to enable those skilled in the art to more fully understand the present invention, but do not limit the present invention in any way. It should be noted that the following embodiments should not be construed as limiting the scope of protection of the present invention. If those skilled in the art make some non-essential improvements and adjustments to the present invention based on the above description, they shall still fall within the scope of protection of the present invention.
[0043] This invention further abstracts the caching process, extracting an overall framework of "caching resource container" + "caching strategy" + "statistics module," thereby improving the scalability and maintainability of the caching framework. It introduces "caching cost-effectiveness," which is determined by algorithms based on resource memory size and load count, thus increasing the cache hit probability.
[0044] Please combine Figure 1 This invention provides a game resource caching method, including:
[0045] S101 retrieves information on the number of times game resources are loaded and their memory usage.
[0046] Specifically, resources such as hero models, scene resources, and interface resources are categorized and managed, including operations such as resource loading, unloading, displaying, and hiding.
[0047] S102, Calculate the cache revenue of the game resources according to the formula: Cache Revenue = Resource Loading Times * Weight + Memory Usage Information * Weight.
[0048] To analyze resource usage and caching effectiveness, this invention includes a statistics module. Developers can obtain data such as resource usage frequency, memory consumption, and cache hit rate through the statistics interface, helping to optimize game performance and caching strategies.
[0049] Specifically, the number of times different game resources are loaded can be counted; the weights in the formula can be adjusted based on the number of resource loads, assigning higher weights to game resources with higher load counts. This allows frequently used game resources to remain in the cache longer, while infrequently used game resources are cleared from the cache earlier, thereby achieving performance optimization.
[0050] S103, add or unload game resources based on the cache revenue.
[0051] Specifically, adding and unloading game resources based on the cache revenue includes: sorting the cache revenue of different game resources from high to low; and optimizing the cache hit rate of different game resources according to the sorting result.
[0052] This invention determines the cost-effectiveness of resource unloading based on caching benefits. For example, if a small effect in a game is repeatedly loaded, it means that the caching benefit of that effect is high, and the hit probability needs to be increased to achieve the expected effect.
[0053] In a preferred embodiment, the method further includes: after the game resources are loaded, automatically managing the lifecycle of the resources based on the cache revenue, automatically unloading unused resources and reclaiming resources that are no longer needed.
[0054] To avoid frequent loading and unloading of resources, the resource manager class employs an automatic management strategy to implement the functionality of a cached resource container. Once a resource is loaded, the resource manager automatically manages its lifecycle, including automatically unloading unused resources and reclaiming resources that are no longer needed. For example, resources are automatically cached when the interface or scene is closed, and automatically unloaded if the cache pool is full. The default caching strategy is based on "caching benefit," with higher cache benefits being reclaimed later.
[0055] In a preferred embodiment, the method further includes: providing developers with a custom caching strategy, wherein the custom caching strategy sorts and manages game resources according to their usage frequency, size, and priority.
[0056] To meet the needs of different games, the solution supports custom caching strategies. Developers can choose appropriate caching strategies based on their actual needs, such as LRU (Least Recently Used) or FIFO (First In First Out). Caching strategies can be sorted and managed based on resource usage frequency, size, priority, and other factors.
[0057] As demonstrated by the above embodiments, this invention provides unified management of game resource loading, unloading, and recycling, reducing issues such as lag, overheating, and memory fragmentation. It efficiently achieves automatic resource management, eliminating the need for developers to manually monitor resource lifecycles. The default "caching benefit" strategy is applicable to most scenarios. Custom caching strategies are supported, allowing developers to flexibly choose the caching strategy best suited to their games. Statistical functions are provided to help developers analyze resource usage and cache hit rates to optimize game performance.
[0058] Please see Figure 2 The present invention also provides a game resource caching device, comprising:
[0059] The acquisition unit 21 is used to acquire the resource loading count and memory usage information of game resources in the game;
[0060] The calculation unit 22 is used to calculate the cache revenue of the game resources according to the formula: Cache revenue = Resource loading times * weight + Memory usage information * weight;
[0061] The add / unload unit 23 is used to add or unload game resources based on the cache revenue.
[0062] In this embodiment, the loading / unloading unit includes:
[0063] The sorting unit is used to sort the caching benefits of different game resources from high to low.
[0064] The optimization unit is used to optimize the cache hit rate of different game resources according to the sorting results.
[0065] In this embodiment, the device further includes:
[0066] The statistics unit is used to count the number of times different game resources are loaded.
[0067] The adjustment unit is used to adjust the weights in the formula according to the number of times the resource is loaded, and to assign higher weights to game resources with higher resource loading times.
[0068] In this embodiment, the device further includes:
[0069] The management unit is used to automatically manage the lifecycle of game resources based on the cache revenue after the game resources are loaded, and to automatically uninstall unused resources and recycle resources that are no longer needed.
[0070] In this embodiment, the device further includes:
[0071] The custom unit is used to provide developers with custom caching strategies, which are sorted and managed according to the usage frequency, size, and priority of game resources.
[0072] This invention also provides a storage medium storing a computer program. When executed by a processor, the computer program implements some or all of the steps in the various embodiments of the game attribute combat power calculation method provided by this invention. The storage medium may be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0073] Those skilled in the art will clearly understand that the techniques in the embodiments of the present invention can be implemented using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solutions in the embodiments of the present invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in various embodiments or certain parts of the embodiments of the present invention.
[0074] The same or similar parts between the various embodiments in this specification can be referred to mutually. In particular, the game attribute combat power calculation device embodiment is basically similar to the method embodiment, so it is described more simply, and the relevant parts can be referred to the description in the method embodiment.
[0075] The embodiments of the present invention described above do not constitute a limitation on the scope of protection of the present invention.
Claims
1. A method for caching game resources, characterized in that, include: Obtain information on the number of times game resources are loaded and their memory usage in the game; According to the formula: Cache benefit = Number of resource loads Weight + Memory Usage Information Weights are used to calculate the caching revenue of the game resources; Adding and unloading game resources based on the aforementioned cache revenue includes: Sort the caching benefits of different game resources from highest to lowest; Optimize the cache hit rate of different game resources according to the sorting results; The method further includes: Count the number of times different game resources are loaded; The weights in the formula are adjusted according to the number of times the resource is loaded, with higher weights assigned to game resources that have a higher number of resource loading times. The method further includes: Once game resources are loaded, the lifecycle of resources is automatically managed based on the cache benefits, automatically unloading unused resources and reclaiming resources that are no longer needed. The method further includes: It provides developers with a custom caching strategy, which sorts and manages game resources based on their usage frequency, size, and priority.
2. An apparatus for executing the game resource caching method of claim 1, characterized in that, include: The acquisition unit is used to acquire information on the number of times game resources are loaded and the memory usage of game resources. The calculation unit is used to calculate the cache benefit based on the formula: Cache benefit = Number of resource loads. Weight + Memory Usage Information Weights are used to calculate the caching revenue of the game resources; An add / unload unit is used to add or unload game resources based on the cached revenue; The loading / unloading unit includes: The sorting unit is used to sort the caching benefits of different game resources from high to low. An optimization unit is used to optimize the cache hit rate of different game resources according to the sorting results; The device further includes: The statistics unit is used to count the number of times different game resources are loaded. An adjustment unit is used to adjust the weights in the formula according to the number of resource loading times, and to assign higher weights to game resources with higher resource loading times. The management unit is used to automatically manage the lifecycle of game resources based on the cache revenue after the game resources are loaded, and to automatically unload unused resources and recycle resources that are no longer needed. The custom unit is used to provide developers with custom caching strategies, which are sorted and managed according to the usage frequency, size, and priority of game resources.
Citation Information
Patent Citations
Image caching method
CN106155591A
Resource cache setting method and system
CN109876436A