Memory management methods, devices, equipment, readable storage media, and program products

CN116775260BActive Publication Date: 2026-08-14TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-10
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0003]本申请针对现有的方式的缺点,提出一种内存管理方法、装置、设备、计算机可读存储介质及计算机程序产品,用于解决如何实现内存池动态分配的问题

Benefits of technology

[0034]确定进程运行中至少一种对象中每种对象占用的第一内存;并基于预设的第一内存池的内存容量,以及每种对象的内存申请,将第一内存池中的第二内存分配给每种对象,确定分配给每种对象的第二内存对应的至少一个第二内存池;基于第一内存和第二内存对应的至少一个第二内存池,将第二内存进行扩容或缩容;扩容以使第二内存对应的第二内存池的数量增加;缩容以使第二内存对应的第二内存池的数量减少;如此,实现了第二内存对应的第二内存池的数量增减,即第二内存对应的第二内存池的动态分配,从而保证了第二内存中内存分配的可靠性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116775260B_ABST
    Figure CN116775260B_ABST
Patent Text Reader

Abstract

This application provides a memory management method, apparatus, device, readable storage medium, and program product, relating to cloud technology, mapping technology, and other fields, with application scenarios including but not limited to cloud gaming. The method includes: determining the first memory occupied by each type of object in at least one object during process execution; allocating second memory from the first memory pool to each object based on the memory capacity of a preset first memory pool and the memory request of each object, and determining at least one second memory pool corresponding to the second memory allocated to each object; expanding or shrinking the second memory based on the at least one second memory pool corresponding to the first memory and the second memory; expanding to increase the number of second memory pools corresponding to the second memory; shrinking to decrease the number of second memory pools corresponding to the second memory; thus, the increase or decrease in the number of second memory pools corresponding to the second memory is realized, i.e., dynamic allocation of the second memory pools.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a memory management method, apparatus, device, readable storage medium, and program product. Background Technology

[0002] Memory pooling is a memory allocation method that uses fixed-size blocks. Current mainstream memory pooling technologies all employ this fixed-size allocation approach. The main method is that when the system starts, a fixed-size memory pool is allocated in the system heap memory or shared memory according to the needs of each module. During system runtime, the required memory is allocated and released within this fixed-size memory pool. Because the size of the memory pool is fixed, if the memory requirements of an object in the game exceed the memory pool's capacity, memory may not be available in the pool, impacting the game's progress and degrading the user experience. Summary of the Invention

[0003] This application addresses the shortcomings of existing methods by proposing a memory management method, apparatus, device, computer-readable storage medium, and computer program product to solve the problem of how to achieve dynamic allocation of memory pools.

[0004] Firstly, this application provides a memory management method, including:

[0005] Determine the first memory occupied by each object in at least one object during process execution; and based on the memory capacity of a preset first memory pool and the memory request of each object, allocate the second memory in the first memory pool to each object, and determine at least one second memory pool corresponding to the second memory allocated to each object;

[0006] Based on at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded or shrunk; expansion increases the number of second memory pools corresponding to the second memory; shrunk decreases the number of second memory pools corresponding to the second memory.

[0007] In one embodiment, the memory capacity of the first memory pool is the maximum shared memory that a process can use; the first memory pool includes a third memory for storing management data of the first memory pool, at least one second memory pool for each type of object, and a fourth memory.

[0008] Each type of object has at least one second memory pool, including memory for storing management data for each of the at least one second memory pools, and memory for storing data for each type of object; the number of each type of object is at least one object, and the data for each type of object includes index data for each object in the at least one object and related data for each object;

[0009] The fourth memory location is free memory.

[0010] In one embodiment, the preset first memory pool includes a fourth memory and at least one second memory pool corresponding to each type of object; the fourth memory is free memory; based on at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded, including:

[0011] Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools;

[0012] If the memory utilization rate of any second memory pool is greater than the preset first ratio threshold, then memory is called from the fourth memory as a new second memory pool, so as to increase the number of second memory pools corresponding to the second memory.

[0013] In one embodiment, the quantity of each type of object is at least one object, and calling memory from the fourth memory as an additional second memory pool for the second memory includes:

[0014] Based on the index data of each object in at least one object, a new second memory pool is added from the fourth memory as the second memory.

[0015] In one embodiment, the preset first memory pool includes a fourth memory and at least one second memory pool corresponding to each type of object; the fourth memory is free memory; based on at least one second memory pool corresponding to the first memory and the second memory, the second memory is scaled down, including:

[0016] Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools;

[0017] If the memory utilization rate of any second memory pool is less than the preset second ratio threshold, then the memory of any second memory pool will be released to the fourth memory, so as to reduce the number of second memory pools corresponding to the second memory.

[0018] In one embodiment, the management data of the first memory pool includes at least one of the following:

[0019] Location information of each second memory pool in at least one second memory pool corresponding to each type of object;

[0020] The memory capacity of each second memory pool in at least one second memory pool corresponding to each type of object;

[0021] The memory utilization rate of each second memory pool in at least one second memory pool corresponding to each type of object. The memory utilization rate is used to characterize the proportion of occupied memory in each second memory pool to the memory capacity of each second memory pool.

[0022] In one embodiment, determining the first memory occupied by each of at least one object during process execution includes:

[0023] Determine the first memory occupied by each type of object in at least one object during the game's execution process, where each type of object is a type of object in the game.

[0024] Secondly, this application provides a memory management device, comprising:

[0025] The first processing module is used to determine the first memory occupied by each object in at least one object during process execution; and based on the memory capacity of a preset first memory pool and the memory request of each object, allocate the second memory in the first memory pool to each object, and determine at least one second memory pool corresponding to the second memory allocated to each object;

[0026] The second processing module is used to expand or shrink the second memory based on at least one second memory pool corresponding to the first memory and the second memory; expanding the second memory increases the number of second memory pools corresponding to the second memory; shrinking the second memory decreases the number of second memory pools corresponding to the second memory.

[0027] Thirdly, this application provides an electronic device, including: a processor, a memory, and a bus;

[0028] A bus is used to connect the processor and memory;

[0029] Memory, used to store operation instructions;

[0030] A processor is used to execute the memory management method of the first aspect of this application by invoking operation instructions.

[0031] Fourthly, this application provides a computer-readable storage medium storing a computer program, which is used to execute the memory management method of the first aspect of this application.

[0032] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the memory management method in the first aspect of this application.

[0033] The technical solution provided in this application has at least the following beneficial effects:

[0034] The first memory occupied by each object in at least one object during process execution is determined; and based on the memory capacity of a preset first memory pool and the memory request of each object, the second memory in the first memory pool is allocated to each object, and at least one second memory pool corresponding to the second memory allocated to each object is determined; based on the at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded or shrunk; expansion increases the number of second memory pools corresponding to the second memory; shrunk decreases the number of second memory pools corresponding to the second memory; thus, the increase or decrease of the number of second memory pools corresponding to the second memory is realized, that is, the dynamic allocation of second memory pools corresponding to the second memory is realized, thereby ensuring the reliability of memory allocation in the second memory. Attached Figure Description

[0035] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.

[0036] Figure 1 A schematic diagram of the architecture of the memory management system provided in an embodiment of this application;

[0037] Figure 2 A flowchart illustrating a memory management method provided in an embodiment of this application;

[0038] Figure 3 A schematic diagram of memory management provided for embodiments of this application;

[0039] Figure 4 A schematic diagram of memory management provided for embodiments of this application;

[0040] Figure 5 A flowchart illustrating another memory management method provided in this application embodiment;

[0041] Figure 6 This application provides a schematic diagram of the structure of a memory management device;

[0042] Figure 7 This application provides a schematic diagram of the structure of an electronic device. Detailed Implementation

[0043] The embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the embodiments described below with reference to the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions of the embodiments of this application.

[0044] Those skilled in the art will understand that, unless otherwise stated, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the terms “comprising” and “including” as used in embodiments of this application mean that the corresponding feature can be implemented as the presented feature, information, data, step, operation, element, and / or component, but do not exclude implementation as other features, information, data, step, operation, element, component, and / or combinations thereof supported by the art. It should be understood that when we say that an element is “connected” or “coupled” to another element, the one element can be directly connected or coupled to the other element, or it can mean that the one element and the other element establish a connection relationship through an intermediate element. Furthermore, “connected” or “coupled” as used herein can include wireless connection or wireless coupling. The term “and / or” as used herein indicates at least one of the items defined by the term; for example, “A and / or B” indicates implementation as “A,” or implementation as “B,” or implementation as “A and B.”

[0045] It is understood that in the specific embodiments of this application, data related to memory management is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0046] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0047] This application provides a memory management method for a memory management system, which relates to cloud technology, mapping, transportation, and other fields. For example, cloud gaming in this application is an application within the cloud technology field. The application scenarios of this memory management method include, but are not limited to, games, such as cloud gaming.

[0048] Cloud gaming, also known as gaming on demand, is an online gaming technology based on cloud computing. It enables thin clients with relatively limited graphics processing and data processing capabilities to run high-quality games. In cloud gaming, the game does not reside on the player's terminal but runs on a cloud server. The cloud server renders the game scene as a video and audio stream, which is then transmitted to the player's terminal via the network. The player's terminal does not need powerful graphics processing and data processing capabilities; it only needs basic streaming media playback capabilities and the ability to receive player input commands and send them to the cloud server.

[0049] Intelligent Traffic Systems (ITS), also known as Intelligent Transportation Systems, effectively integrate advanced science and technology (information technology, computer technology, data communication technology, sensor technology, electronic control technology, automatic control theory, operations research, artificial intelligence, etc.) into transportation, service control, and vehicle manufacturing. This strengthens the connection between vehicles, roads, and users, thereby forming a comprehensive transportation system that ensures safety, improves efficiency, enhances the environment, and saves energy.

[0050] To better understand and explain the solutions of the embodiments of this application, some technical terms involved in the embodiments of this application will be briefly explained below.

[0051] Shared memory: Shared memory refers to a large amount of memory on a multi-processor machine that can be accessed by different central processing units. It is usually used for data sharing between processes or communication between multiple processes. Because shared memory has the characteristic that if a process crashes and restarts, it can still read the original information from the shared memory, it is widely used in game development as a memory storage method for game objects.

[0052] Memory pooling: Memory pooling is a memory allocation method that uses fixed-size blocks. It avoids the memory fragmentation problems associated with common memory allocation methods like `malloc` or `free`, as well as the system overhead of allocating and releasing memory. Before actually using memory, a certain number of equal-sized (generally) memory blocks are allocated as reserves. When new memory is needed, a portion of the memory is allocated from the pool; if the pool is insufficient, more memory is requested. A significant advantage of this approach is improved memory allocation efficiency.

[0053] A process is a single execution of a program on a specific set of data in a computer. It is the basic unit for resource allocation and scheduling in a system and forms the foundation of the operating system architecture. In early process-oriented computer architectures, the process was the fundamental execution entity of a program; in contemporary thread-oriented computer architectures, the process is a container for threads. A program is a description of instructions, data, and their organization; a process is the entity that implements a program.

[0054] SDK (Software Development Kit) is generally a collection of development tools used by software engineers to create application software for specific software packages, frameworks, hardware platforms, and operating systems. In a broader sense, software development tools refer to a collection of related documents, examples, and tools that assist in developing a particular type of software. An SDK is a collection of development tools used by software engineers to create application software for specific software packages, frameworks, hardware platforms, and operating systems. Generally, an SDK is the SDK used to develop applications for the Windows platform. An SDK can simply provide some files that provide an application programming interface (API) for a programming language, but it may also include complex hardware that can communicate with an embedded system. Common tools include utilities for debugging and other purposes. SDKs also often include sample code, supporting technical annotations, or other supporting documentation to clarify ambiguities for basic reference materials.

[0055] The solutions provided in this application relate to cloud technology. The technical solutions of this application will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0056] To better understand the solution provided in the embodiments of this application, the solution will be described below in conjunction with a specific application scenario.

[0057] In one embodiment, Figure 1 The diagram illustrates an architecture of a memory management system applicable to embodiments of this application. It is understood that the memory management method provided in these embodiments can be applied to, but is not limited to, applications such as... Figure 1 In the application scenarios shown.

[0058] In this example, as Figure 1As shown, the architecture of the memory management system in this example may include, but is not limited to, terminal 10 and server 20. During the game's execution in terminal 10, terminal 10 and server 20 can interact via a network. Server 20 determines the first memory occupied by each object in at least one of the objects running in the process. Based on the memory capacity of a preset first memory pool and the memory requests of each object, server 20 allocates second memory from the first memory pool to each object, determining at least one second memory pool corresponding to the second memory allocated to each object. Based on the at least one second memory pool corresponding to the first and second memory, server 20 expands or shrinks the second memory. Expanding increases the number of second memory pools corresponding to the second memory; shrinking decreases the number of second memory pools corresponding to the second memory. This achieves the dynamic allocation of the second memory pools corresponding to the second memory, ensuring smooth gameplay in terminal 10 and improving the user experience.

[0059] Server 20 can be a Linux server, a Windows server, etc.

[0060] It is understood that the above is only one example, and this embodiment is not limited here.

[0061] The terminal can be a smartphone (such as an Android phone, iOS phone, etc.), a mobile phone emulator, a tablet computer, a laptop computer, a digital broadcast receiver, a MID (Mobile Internet Device), a PDA (Personal Digital Assistant), etc. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server or server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0062] Cloud computing is a computing model that distributes computing tasks across a large pool of computers, enabling various application systems to access computing power, storage space, and information services as needed. The network providing these resources is called the "cloud." From the user's perspective, resources in the "cloud" appear infinitely scalable, readily available, on-demand, and expandable, with payment based on usage.

[0063] As a provider of fundamental cloud computing capabilities, a cloud resource pool (referred to as a cloud platform, generally called an IaaS (Infrastructure as a Service) platform) is established. Various types of virtual resources are deployed in the resource pool for external customers to choose from. The cloud resource pool mainly includes: computing devices (virtualized machines containing operating systems), storage devices, and network devices.

[0064] Based on logical function, a PaaS (Platform as a Service) layer can be deployed on top of the IaaS (Infrastructure as a Service) layer, and a SaaS (Software as a Service) layer can be deployed on top of the PaaS layer. Alternatively, SaaS can be deployed directly on top of IaaS. PaaS is a platform for running software, such as databases and web containers. SaaS refers to various types of business software, such as web portals and bulk SMS senders. Generally speaking, SaaS and PaaS are upper layers compared to IaaS.

[0065] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.

[0066] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and intelligent transportation.

[0067] Artificial intelligence cloud services are generally also known as AIaaS (AI as a Service). This is currently a mainstream service model for artificial intelligence platforms. Specifically, AIaaS platforms break down several common AI services and provide them as independent or packaged services in the cloud. This service model is similar to opening an AI-themed marketplace: all developers can access and use one or more AI services provided by the platform through API interfaces. Some experienced developers can also use the AI ​​framework and AI infrastructure provided by the platform to deploy and maintain their own dedicated cloud AI services.

[0068] The aforementioned networks may include, but are not limited to, wired networks and wireless networks. Wired networks include local area networks (LANs), metropolitan area networks (MANs), and wide area networks (WANs). Wireless networks include Bluetooth, Wi-Fi, and other networks that enable wireless communication. Specific details can be determined based on actual application scenario requirements and are not limited here.

[0069] See Figure 2 , Figure 2 This illustration shows a flowchart of a memory management method provided in an embodiment of this application. This method can be executed by any electronic device, such as a server. As an optional implementation, the method can be executed by a server. For ease of description, the following descriptions of some optional embodiments will use a server as the execution subject of the method. Figure 2 As shown, the memory management method provided in this application includes the following steps:

[0070] S201, determine the first memory occupied by each object in at least one object during process execution; and based on the memory capacity of a preset first memory pool and the memory request of each object, allocate the second memory in the first memory pool to each object, and determine at least one second memory pool corresponding to the second memory allocated to each object.

[0071] Specifically, a process can be a process within a game. A game process can contain various objects, such as players and monsters. Each type of object can exist in multiple quantities. For example, a game process might have three objects: Player A, Player B, and Player C. Player A, Player B, and Player C all belong to the "player" object type. Alternatively, a game process might have seven objects: Player A, Player B, Player C, Monster D, Monster E, Monster F, and Monster G. Player A, Player B, and Player C all belong to the "player" object type, while Monster D, Monster E, Monster F, and Monster G all belong to the "monster" object type. Therefore, a game process contains two types of objects: players and monsters. There are three players and four monsters.

[0072] For a given type of object, the memory currently being used by that object is designated as the first memory, and the memory that has been pre-allocated for that object is designated as the second memory. The second memory can be larger than the first memory.

[0073] S202, based on at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded or shrunk; expansion increases the number of second memory pools corresponding to the second memory; shrunk decreases the number of second memory pools corresponding to the second memory.

[0074] Specifically, there can be multiple objects in the game's process, and each object can be pre-allocated memory, i.e., secondary memory; the secondary memory of each object can be expanded or shrunk in real time during the game's process.

[0075] In this embodiment, a first memory is determined for each type of object in at least one object during process execution; and based on the memory capacity of a preset first memory pool and the memory request of each type of object, a second memory in the first memory pool is allocated to each type of object, and at least one second memory pool corresponding to the second memory allocated to each type of object is determined; based on the at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded or shrunk; expansion increases the number of second memory pools corresponding to the second memory; shrinking decreases the number of second memory pools corresponding to the second memory; thus, the increase or decrease of the number of second memory pools corresponding to the second memory is realized, that is, the dynamic allocation of second memory pools corresponding to the second memory is achieved, thereby ensuring the reliability of memory allocation in the second memory.

[0076] In one embodiment, determining the first memory occupied by each of at least one object during process execution includes:

[0077] Determine the first memory occupied by each type of object in at least one object during the game's execution process, where each type of object is a type of object in the game.

[0078] Specifically, during the game's execution, the first memory includes the memory occupied by each type of object. For example, if there are 100 of a certain type of object, then the first memory includes the memory occupied by these 100 objects.

[0079] In one embodiment, the memory capacity of the first memory pool is the maximum shared memory that a process can use; the first memory pool includes a third memory for storing management data of the first memory pool, at least one second memory pool for each type of object, and a fourth memory.

[0080] Each type of object has at least one second memory pool, including memory for storing management data for each of the at least one second memory pools, and memory for storing data for each type of object; the number of each type of object is at least one object, and the data for each type of object includes index data for each object in the at least one object and related data for each object;

[0081] The fourth memory location is free memory.

[0082] Specifically, the relevant data for each object can be the game data for each object.

[0083] In one embodiment, the process initialization provided in this application includes steps A1-A4:

[0084] Step A1: The process begins initialization.

[0085] Specifically, the process in cloud gaming begins initialization.

[0086] Step A2: Request shared memory.

[0087] Specifically, a maximum shared memory space that the current process can use is pre-allocated, and this maximum shared memory space is used as the memory capacity of the first memory pool (first-level memory pool). For each type of object, the system allocates the memory capacity of the memory pool required for that type of object, i.e., the capacity of the second memory pool for each type of object. The second memory pool can be the memory of multiple second memory pools (second-level memory pools). For example, the system can be a player system, a monster system, etc., where the player system can be a general term for the game logic operations performed on player objects. The first memory pool can be the first-level memory pool, and the second memory pool can be the second-level memory pool.

[0088] The management unit of the first-level memory pool determines the memory capacity required by each object based on the system's application for each object, and constructs the initial shared memory pool for each object, which is the second-level memory pool for each object. The number of second-level memory pools for each object can be at least one, and the management unit of the first-level memory pool can correspond to the management data of the first-level memory pool.

[0089] Step A3: The second-level memory pool for each type of object is initialized.

[0090] Specifically, the management unit of the second-level memory pool for an object performs object partitioning and management within the second-level memory pool based on the quantity and type of that object, and establishes various related index information. The management unit of the second-level memory pool can maintain the size of the second-level memory pool, memory utilization, and establish index relationships such as allocated data and allocable data through object index data. The management unit of the second-level memory pool can correspond to the management data of the second-level memory pool, or it can be the management data of the second-level memory pool itself.

[0091] Step A4: Process initialization is complete, and the process begins running.

[0092] Specifically, the layout of the first-level memory pool (first memory pool) and the second-level memory pool (second memory pool) after process initialization is as follows: Figure 3 As shown, the first-level memory pool includes memory (third memory) storing the management data of the first-level memory pool (the management data corresponding to the management unit of the first-level memory pool), second-level memory pool A corresponding to type A objects, second-level memory pool B corresponding to type B objects, and free space (fourth memory). The management data of the first-level memory pool includes the location information of second-level memory pool A, the location information of second-level memory pool B, the memory capacity of second-level memory pool A, the memory capacity of second-level memory pool B, the memory utilization rate of second-level memory pool A, and the memory utilization rate of second-level memory pool B, etc.

[0093] The second-level memory pool A includes memory for storing management data (management data corresponding to the management units of the second-level memory pool A) and memory for storing data for type A objects (data of the objects corresponding to the second-level memory pool A). There are multiple type A objects, and their data includes the index data of each object and the game data for each object. The second-level memory pool B includes memory for storing management data (management data corresponding to the management units of the second-level memory pool B) and memory for storing data for type B objects (data of the objects corresponding to the second-level memory pool B). There are multiple type B objects, and their data includes the index data of each object and the game data for each object. The memory in the free space has not yet been allocated to type A or type B objects; this free space is reserved. For example, the type of object is a player; the index data of player C can be used to describe the relationship between player C and other players, and can also be used to describe the memory usage and memory allocation before and after memory scaling (expansion or reduction) for player C; the game data of each player can be the player's level, the player's equipment, the player's actions in the game, etc.

[0094] In one embodiment, an index relationship of allocated memory is established using the object's index data. The object's index data can organize the game data of multiple players within a second-level memory pool; that is, the object's index data can be a data structure. For example, the management data of the second-level memory pool records the addresses of allocated memory, each address pointing to the index data of a specific object. This index data can then point to the address of another index data, forming a linked list structure that can be used to represent the addresses of all allocated memory.

[0095] In one embodiment, the preset first memory pool includes a fourth memory and at least one second memory pool corresponding to each type of object; the fourth memory is free memory; based on at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded, including:

[0096] Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools;

[0097] If the memory utilization rate of any second memory pool is greater than the preset first ratio threshold, then memory is called from the fourth memory as a new second memory pool, so as to increase the number of second memory pools corresponding to the second memory.

[0098] Specifically, because the estimation of memory allocated in the memory pool when the game starts may be inaccurate, or the users the system needs to serve may suddenly change, the memory allocated in the memory pool may change. Therefore, it is necessary to check the capacity of the memory pool, that is, to determine the memory utilization rate of the second-level memory pool; if the memory utilization rate of the second-level memory pool is greater than a preset first ratio threshold, then expansion is performed. Figure 4 As shown, for example, if memory for 100 players is allocated to a second-level memory pool A1 (the second memory is the memory for 100 players, meaning the capacity of the second memory is the same as the memory capacity of the second-level memory pool A1), and users use the memory for 81 players (the first memory is the memory for 81 players), then the memory utilization rate of the second-level memory pool A1 is 81%. Expanding the pool is a time-consuming operation; therefore, it needs to be processed in advance. If the preset first ratio threshold is 80%, and the memory utilization rate of the second-level memory pool A1 is 81%, which is greater than the preset first ratio threshold of 80%, then memory is drawn from the fourth memory (free space) to create a new second memory pool A2. The capacity of this second memory pool A2 can be set to half the capacity of the second memory pool A1. After adding a second memory pool A2, the memory capacity of the second memory pool is the sum of the memory capacity of the second-level memory pool A1 and the memory capacity of the second memory pool A2.

[0099] The layout of the first-level memory pool (first memory pool) and the second-level memory pool (second memory pool) after the second memory pool has been expanded, as follows: Figure 4 As shown, the first-level memory pool includes memory (third memory) storing the management data of the first-level memory pool (the management data corresponding to the management unit of the first-level memory pool), second-level memory pool A1 corresponding to type A objects, second-level memory pool A2 corresponding to type A objects, second-level memory pool B corresponding to type B objects, and free space (fourth memory). The management data of the first-level memory pool includes the location information of the second-level memory pool A1, the location information of the second-level memory pool A2, the location information of the second-level memory pool B, the memory capacity of the second-level memory pool A1, the memory capacity of the second-level memory pool A2, the memory capacity of the second-level memory pool B, the memory utilization rate of the second-level memory pool A1, the memory utilization rate of the second-level memory pool A2, and the memory utilization rate of the second-level memory pool B, etc.

[0100] The second-level memory pool A1 includes memory for storing management data of the second-level memory pool A (management data corresponding to the management unit of the second-level memory pool A1) and memory for storing data of type A objects (data of objects corresponding to the second-level memory pool A1). The second-level memory pool A2 includes memory for storing management data of the second-level memory pool A2 (management data corresponding to the management unit of the second-level memory pool A2) and memory for storing data of type A objects (data of objects corresponding to the second-level memory pool A2). There are multiple type A objects, and the data of type A objects includes the index data of each object and the game data of each object. The second-level memory pool B includes memory for storing management data of the second-level memory pool B (management data corresponding to the management unit of the second-level memory pool B) and memory for storing data of type B objects (data of objects corresponding to the second-level memory pool B). There are multiple type B objects, and the data of type B objects includes the index data of each object and the game data of each object.

[0101] It should be noted that the management unit of the first-level memory pool (first memory pool) will create a second-level memory pool (second memory pool A2) in the free space (fourth memory) and update the management data of the first-level memory pool. For example, the management unit of the first-level memory pool creates a management unit for the second-level memory pool, and the management unit of the first-level memory pool re-maintains the association relationships between the various second-level memory pools. In this way, memory allocation and memory release can be performed in the newly added second-level memory pool (second memory pool A2).

[0102] In one embodiment, if the memory capacity of the first-level memory pool cannot meet the memory requirements of a running process, a system alarm will be generated.

[0103] In one embodiment, the quantity of each type of object is at least one object, and calling memory from the fourth memory as an additional second memory pool for the second memory includes:

[0104] Based on the index data of each object in at least one object, a new second memory pool is added from the fourth memory as the second memory.

[0105] In one embodiment, the management data of the second memory pool records the address of the index data of the next allocatable memory A. Then, the index data of memory A records the address of the index data of the next allocatable memory B, thus forming a linked list. If there is a memory allocation requirement, suitable memory can be quickly found and allocated from this linked list.

[0106] In one embodiment, the preset first memory pool includes a fourth memory and at least one second memory pool corresponding to each type of object; the fourth memory is free memory; based on at least one second memory pool corresponding to the first memory and the second memory, the second memory is scaled down, including:

[0107] Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools;

[0108] If the memory utilization rate of any second memory pool is less than the preset second ratio threshold, then the memory of any second memory pool will be released to the fourth memory, so as to reduce the number of second memory pools corresponding to the second memory.

[0109] Specifically, if the memory utilization rate of the second-level memory pool for the same object is too low, and the management unit of the first-level memory pool detects that the first-level memory pool includes multiple second-level memory pools for the same object, it will automatically shrink the second-level memory pool, which is the reverse process of expansion. After shrinking, a portion of the memory will be returned to the free space. If the memory utilization rate of one of the multiple second-level memory pools is less than a preset second ratio threshold, the memory of that second-level memory pool will be released to the free space (fourth memory). For example, the second ratio threshold is 30%, and there are three second-level memory pools for the same object, namely the first second-level memory pool, the second second-level memory pool, and the third second-level memory pool. The first second-level memory pool can be built before the second second-level memory pool, and the second second-level memory pool can be built before the third second-level memory pool. If the memory utilization rate of the second secondary memory pool is 20%, which is less than the second ratio threshold of 30%, then the third secondary memory pool will be shrunk down. After the third secondary memory pool is shrunk down, if the memory utilization rate of the first secondary memory pool is also less than the second ratio threshold of 30%, then the second secondary memory pool will also be shrunk down, leaving only the first secondary memory pool.

[0110] In one embodiment, the management data of the first memory pool includes at least one of the following:

[0111] Location information of each second memory pool in at least one second memory pool corresponding to each type of object;

[0112] The memory capacity of each second memory pool in at least one second memory pool corresponding to each type of object;

[0113] The memory utilization rate of each second memory pool in at least one second memory pool corresponding to each type of object. The memory utilization rate is used to characterize the proportion of occupied memory in each second memory pool to the memory capacity of each second memory pool.

[0114] Specifically, the location information of the second memory pool includes memory address information, the memory capacity of the second memory pool can be used to characterize the size of the second memory pool, and the memory utilization rate of the second memory pool can be used to characterize the proportion of the number of memory objects allocated by the second memory pool to the total number of memory objects that can be allocated; wherein, the second memory pool can be a second-level memory pool.

[0115] Applying the embodiments of this application has at least the following beneficial effects:

[0116] By managing the memory pool space through the management units of the first-level memory pool and the second-level memory pool, it can be ensured that the required memory can be flexibly and effectively allocated regardless of the size setting of the second-level memory pool, provided that there is free space in the first-level memory pool. Expanding or shrinking the second memory (second-level memory pool) greatly improves the effectiveness and reliability of memory pool allocation under the same memory environment, and the dynamic allocation process of the memory pool is transparent and imperceptible to the user interface.

[0117] To better understand the methods provided in the embodiments of this application, the solutions of the embodiments of this application will be further explained below with reference to specific application scenarios.

[0118] The method provided in this application embodiment can be applied to game scenarios, such as cloud gaming.

[0119] In one embodiment, the method provided in this application has been applied to the memory data management of each process of the game's backend server. It has undergone online testing and operation with hundreds of thousands of people online at the same time. The test results show that the method provided in this application can efficiently support the allocation and use of memory under high concurrency online. When the actual pre-allocated memory pool space needs to be adjusted, the memory pool can be flexibly scaled automatically.

[0120] In one embodiment, the method provided in this application is integrated into an engineering project as an SDK. When the game process starts, the user can initialize the appropriate memory pool according to the user-side interface (software interface information in the SDK). When the game process runs, the user can allocate and release memory in the memory pool according to the user-side interface.

[0121] In one embodiment, during the actual execution of a process, memory object allocation and deallocation operations occur within the memory pool. Memory object allocation refers to a user requesting memory for a specific object, while memory object deallocation refers to the user returning the memory for an object to the memory pool when no longer needing it. For example, if the memory pool contains 100 player objects, the user might dynamically request memory for one of those player objects; or, once the user has finished using the memory, return the memory for that player object to the memory pool. The memory allocation operation is performed in the second-level memory pool, based on index data; the memory deallocation operation is also performed in the second-level memory pool, based on index data.

[0122] See Figure 5 , Figure 5This illustration shows a flowchart of a memory management method provided in an embodiment of this application. This method can be executed by any electronic device, such as a server. As an optional implementation, the method can be executed by a server. For ease of description, the following descriptions of some optional embodiments will use a server as the execution subject of the method. Figure 5 As shown, the memory management method provided in this application includes the following steps:

[0123] S501 requests shared memory space from the operating system when the game process starts.

[0124] Specifically, a maximum shared memory space that the current game process can use is pre-allocated, and this maximum shared memory space is used as the memory capacity of the first memory pool (first-level memory pool). The lifecycle of this shared memory is consistent with the lifecycle of the process.

[0125] S502 uses a shared memory space to build a two-level memory pool.

[0126] Specifically, after a process starts, the system corresponding to a certain object requests a second-level memory pool from the management unit of the first-level memory pool, and the management unit of the first-level memory pool will build a second-level memory pool for that object.

[0127] The management unit of the first-level memory pool manages each second-level memory pool. The management unit of the first-level memory pool is responsible for managing the allocation, release, and scaling (expanding or shrinking) of each second-level memory pool. The management unit of the second-level memory pool manages the second-level memory pool itself. The management unit of the second-level memory pool is responsible for the allocation, release, search, traversal and other operations of objects within the second-level memory pool.

[0128] During the game's execution, the S503 allocates and releases memory in the second-level memory pool for a specific object through the management unit of the second-level memory pool.

[0129] Applying the embodiments of this application has at least the following beneficial effects:

[0130] The memory pool space is managed through the management units of the first-level memory pool and the second-level memory pool. Based on the memory utilization rate of the second-level memory pool, the second-level memory pool will be automatically scaled up or down to ensure the reliability of memory allocation.

[0131] This application also provides a memory management device, the structural schematic diagram of which is shown below. Figure 6 As shown, the memory management device 60 includes a first processing module 601 and a second processing module 602.

[0132] The first processing module 601 is used to determine the first memory occupied by each object in at least one object during process execution; and based on the memory capacity of a preset first memory pool and the memory request of each object, allocate the second memory in the first memory pool to each object, and determine at least one second memory pool corresponding to the second memory allocated to each object.

[0133] The second processing module 602 is used to expand or shrink the second memory based on at least one second memory pool corresponding to the first memory and the second memory; expanding the second memory increases the number of second memory pools corresponding to the second memory; shrinking the second memory decreases the number of second memory pools corresponding to the second memory.

[0134] In one embodiment, the memory capacity of the first memory pool is the maximum shared memory that a process can use; the first memory pool includes a third memory for storing management data of the first memory pool, at least one second memory pool for each type of object, and a fourth memory.

[0135] Each type of object has at least one second memory pool, including memory for storing management data for each of the at least one second memory pools, and memory for storing data for each type of object; the number of each type of object is at least one object, and the data for each type of object includes index data for each object in the at least one object and related data for each object;

[0136] The fourth memory location is free memory.

[0137] In one embodiment, the preset first memory pool includes a fourth memory pool and at least one second memory pool corresponding to each type of object; the fourth memory pool is free memory; the second processing module 602 is specifically used for:

[0138] Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools;

[0139] If the memory utilization rate of any second memory pool is greater than the preset first ratio threshold, then memory is called from the fourth memory as a new second memory pool, so as to increase the number of second memory pools corresponding to the second memory.

[0140] In one embodiment, the quantity of each type of object is at least one object, and the second processing module 602 is specifically used for:

[0141] Based on the index data of each object in at least one object, a new second memory pool is added from the fourth memory as the second memory.

[0142] In one embodiment, the preset first memory pool includes a fourth memory pool and at least one second memory pool corresponding to each type of object; the fourth memory pool is free memory; the second processing module 602 is specifically used for:

[0143] Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools;

[0144] If the memory utilization rate of any second memory pool is less than the preset second ratio threshold, then the memory of any second memory pool will be released to the fourth memory, so as to reduce the number of second memory pools corresponding to the second memory.

[0145] In one embodiment, the management data of the first memory pool includes at least one of the following:

[0146] Location information of each second memory pool in at least one second memory pool corresponding to each type of object;

[0147] The memory capacity of each second memory pool in at least one second memory pool corresponding to each type of object;

[0148] The memory utilization rate of each second memory pool in at least one second memory pool corresponding to each type of object. The memory utilization rate is used to characterize the proportion of occupied memory in each second memory pool to the memory capacity of each second memory pool.

[0149] In one embodiment, determining the first memory occupied by each of at least one object during process execution includes:

[0150] Determine the first memory occupied by each type of object in at least one object during the game's execution process, where each type of object is a type of object in the game.

[0151] Applying the embodiments of this application has at least the following beneficial effects:

[0152] The first memory occupied by each object in at least one object during process execution is determined; and based on the memory capacity of a preset first memory pool and the memory request of each object, the second memory in the first memory pool is allocated to each object, and at least one second memory pool corresponding to the second memory allocated to each object is determined; based on the at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded or shrunk; expansion increases the number of second memory pools corresponding to the second memory; shrunk decreases the number of second memory pools corresponding to the second memory; thus, the increase or decrease of the number of second memory pools corresponding to the second memory is realized, that is, the dynamic allocation of second memory pools corresponding to the second memory is realized, thereby ensuring the reliability of memory allocation in the second memory.

[0153] This application also provides an electronic device, the structural schematic diagram of which is shown below. Figure 7 As shown, Figure 7 The illustrated electronic device 4000 includes a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, for example, via a bus 4002. Optionally, the electronic device 4000 may further include a transceiver 4004, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver 4004 is not limited to one type, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of this application.

[0154] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0155] Bus 4002 may include a pathway for transmitting information between the aforementioned components. Bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 4002 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0156] The memory 4003 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium capable of carrying or storing computer programs and capable of being read by a computer, without limitation herein.

[0157] The memory 4003 stores computer programs that execute embodiments of this application, and its execution is controlled by the processor 4001. The processor 4001 executes the computer programs stored in the memory 4003 to implement the steps shown in the foregoing method embodiments.

[0158] Electronic devices include, but are not limited to, servers.

[0159] Applying the embodiments of this application has at least the following beneficial effects:

[0160] The first memory occupied by each object in at least one object during process execution is determined; and based on the memory capacity of a preset first memory pool and the memory request of each object, the second memory in the first memory pool is allocated to each object, and at least one second memory pool corresponding to the second memory allocated to each object is determined; based on the at least one second memory pool corresponding to the first memory and the second memory, the second memory is expanded or shrunk; expansion increases the number of second memory pools corresponding to the second memory; shrunk decreases the number of second memory pools corresponding to the second memory; thus, the increase or decrease of the number of second memory pools corresponding to the second memory is realized, that is, the dynamic allocation of second memory pools corresponding to the second memory is realized, thereby ensuring the reliability of memory allocation in the second memory.

[0161] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the steps and corresponding content of the aforementioned method embodiments.

[0162] This application also provides a computer program product, including a computer program that, when executed by a processor, can implement the steps and corresponding content of the aforementioned method embodiments.

[0163] Based on the same principles as the methods provided in the embodiments of this application, the embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in any of the optional embodiments of this application described above.

[0164] It should be understood that although arrows indicate various operation steps in the flowcharts of this application's embodiments, the order in which these steps are implemented is not limited to the order indicated by the arrows. Unless explicitly stated herein, in some implementation scenarios of this application's embodiments, the implementation steps in each flowchart can be executed in other orders as required. Furthermore, some or all steps in each flowchart, based on the actual implementation scenario, may include multiple sub-steps or multiple stages. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage can also be executed at different times. In scenarios where execution times differ, the execution order of these sub-steps or stages can be flexibly configured according to requirements, and this application's embodiments do not limit this.

[0165] The above description is only an optional implementation method for some implementation scenarios of this application. It should be noted that for those skilled in the art, other similar implementation methods based on the technical concept of this application without departing from the technical concept of this application also fall within the protection scope of the embodiments of this application.

Claims

1. A memory management method, characterized in that, include: Determine the first memory occupied by each of at least one objects during process execution; Based on the memory capacity of the preset first memory pool and the memory request of each type of object, the second memory in the first memory pool is allocated to each type of object, and at least one second memory pool corresponding to the second memory allocated to each type of object is determined, wherein each type of object is an object in the game; The first memory pool includes a third memory for storing management data of the first memory pool, at least one second memory pool corresponding to each type of object, and a fourth memory; Based on at least one second memory pool corresponding to the first memory and the second memory, determine the memory utilization rate of any one of the at least one second memory pools; If the memory utilization rate of any of the second memory pools is greater than a preset first ratio threshold, then memory is called from the fourth memory pool as a new second memory pool for the second memory pool. If the memory utilization rate of any of the second memory pools is less than a preset second ratio threshold, then the memory of any of the second memory pools will be released to the fourth memory.

2. The method according to claim 1, characterized in that, The memory capacity of the first memory pool is the maximum shared memory that the process can use; The at least one second memory pool corresponding to each type of object includes memory for storing management data of each of the at least one second memory pools, and memory for storing data of each type of object; the number of each type of object is at least one object, and the data of each type of object includes index data of each object in the at least one object and related data of each object; The fourth memory is free memory.

3. The method according to claim 1, characterized in that, The quantity of each type of object is at least one object, and the step of calling memory from the fourth memory as an additional second memory pool for the second memory includes: Based on the index data of each object in the at least one object, memory is called from the fourth memory as an additional second memory pool for the second memory.

4. The method according to claim 1, characterized in that, The management data for the first memory pool includes at least one of the following: The location information of each second memory pool in at least one second memory pool corresponding to each type of object; The memory capacity of each second memory pool in at least one second memory pool corresponding to each type of object; The memory utilization rate of each second memory pool in at least one second memory pool corresponding to each type of object, wherein the memory utilization rate is used to characterize the proportion of the occupied memory of each second memory pool to the memory capacity of each second memory pool.

5. The method according to claim 1, characterized in that, Determining the first memory occupied by each of at least one object during process execution includes: Determine the first memory occupied by each of at least one objects during the game's execution.

6. A memory management device, characterized in that, include: The first processing module is used to determine the first memory occupied by each of at least one objects in the process running; Based on the memory capacity of the preset first memory pool and the memory request of each type of object, the second memory in the first memory pool is allocated to each type of object, and at least one second memory pool corresponding to the second memory allocated to each type of object is determined, wherein each type of object is an object in the game; The first memory pool includes a third memory for storing management data of the first memory pool, at least one second memory pool corresponding to each type of object, and a fourth memory; The second processing module is used to determine the memory utilization rate of any one of the at least one second memory pools based on the first memory and the second memory. If the memory utilization rate of any of the second memory pools is greater than a preset first ratio threshold, then memory is called from the fourth memory pool as a new second memory pool for the second memory pool. If the memory utilization rate of any of the second memory pools is less than a preset second ratio threshold, then the memory of any of the second memory pools will be released to the fourth memory.

7. The apparatus according to claim 6, characterized in that, The memory capacity of the first memory pool is the maximum shared memory that the process can use; The at least one second memory pool corresponding to each type of object includes memory for storing management data of each of the at least one second memory pools, and memory for storing data of each type of object; the number of each type of object is at least one object, and the data of each type of object includes index data of each object in the at least one object and related data of each object; The fourth memory is free memory.

8. The apparatus according to claim 6, characterized in that, The quantity of each type of object is at least one object. When the second processing module calls memory from the fourth memory as an additional second memory pool for the second memory, it is specifically used for: Based on the index data of each object in the at least one object, memory is called from the fourth memory as an additional second memory pool for the second memory.

9. The apparatus according to claim 6, characterized in that, The management data for the first memory pool includes at least one of the following: The location information of each second memory pool in at least one second memory pool corresponding to each type of object; The memory capacity of each second memory pool in at least one second memory pool corresponding to each type of object; The memory utilization rate of each second memory pool in at least one second memory pool corresponding to each type of object, wherein the memory utilization rate is used to characterize the proportion of the occupied memory of each second memory pool to the memory capacity of each second memory pool.

10. The apparatus according to claim 6, characterized in that, When determining the first memory occupied by each of at least one object during process execution, the first processing module is specifically used for: Determine the first memory occupied by each of at least one objects during the game's execution.

11. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1-5.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-5.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-5.

Citation Information

Patent Citations

  • Memory management method and device, electronic device and computer readable storage medium

    CN110008021A

  • Memory scheduling method, apparatus and device, and storage medium

    CN110427273A