Memory allocation method and device, equipment and storage medium

By creating an initial memory pool while the application is running and creating new memory pools dynamically, the problem of inefficient memory allocation in the existing technology is solved, and more efficient memory allocation and better application performance is achieved.

CN119806790APending Publication Date: 2025-04-11BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311310773.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-10
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

The existing memory allocation scheme has low memory allocation efficiency and is difficult to meet the memory management needs of smart terminals in multi-threaded scenarios.

Method used

Memory allocation of threads is performed based on these memory pools by creating a preset number of initial memory pools when the application is running, and creating new memory pools through dynamic parameter release functions.

Benefits of technology

Improves the concurrency and efficiency of local memory allocation, reduces competition for multi-threaded locks, and improves application performance and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806790A_ABST
    Figure CN119806790A_ABST
Patent Text Reader

Abstract

The invention provides a memory allocation method and device, equipment and a storage medium, and relates to the technical field of computers. The method comprises the steps that when an application program runs, a first preset number of initial memory pools are created by starting a memory allocator of a local memory, the first preset number is determined during compiling, a first dynamic parameter value is issued by calling a preset parameter issuing function, and a second preset number of newly-added memory pools are created, the first dynamic parameter value is used for indicating the new memory pool, and performing thread memory allocation based on the initial memory pool and the new memory pool. By adopting the technical scheme, the concurrency of local memory allocation can be improved, and the memory allocation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a memory allocation method, apparatus, device, and storage medium. Background Art

[0002] With the rapid development of smart terminal technology, the applications that can run on smart terminals are becoming more and more abundant.

[0003] During the running of the application, the reasonable allocation of memory can ensure the good performance of the smart terminal and the application. For native memory, the corresponding memory allocator usually allocates memory. For the memory management requirements in multi-threaded scenarios, the memory allocator can use multiple memory pools to distribute threads among different memory pools, thereby reducing the competition for memory access. For memory allocation within a memory pool, a local lock can be used to protect concurrent access.

[0004] However, the memory allocation efficiency of the current memory allocation scheme is low and needs to be improved. Summary of the invention

[0005] The embodiments of the present disclosure provide a memory allocation method, apparatus, device and storage medium, which can optimize the existing memory allocation scheme.

[0006] In a first aspect, an embodiment of the present disclosure provides a memory allocation method, including:

[0007] When the application is running, a first preset number of initial memory pools is created by starting a memory allocator of the local memory, wherein the first preset number is determined at compile time;

[0008] Creating a second preset number of newly added memory pools by calling a preset parameter sending function to send a first dynamic parameter value, wherein the first dynamic parameter value is used to indicate a newly created memory pool;

[0009] Memory allocation for threads is performed based on the initial memory pool and the newly added memory pool.

[0010] In a second aspect, the embodiment of the present disclosure further provides a memory allocation device, including:

[0011] An initial memory pool creation module, used to create a first preset number of initial memory pools by starting a memory allocator of a local memory when the application is running, wherein the first preset number is determined at compile time;

[0012] A newly added memory pool creation module is used to issue a first dynamic parameter value by calling a preset parameter issuing function to create a second preset number of newly added memory pools, wherein the first dynamic parameter value is used to indicate a newly created memory pool;

[0013] A memory allocation module is used to allocate memory for threads based on the initial memory pool and the newly added memory pool.

[0014] In a third aspect, an embodiment of the present disclosure further provides an electronic device, the electronic device comprising:

[0015] one or more processors;

[0016] a storage device for storing one or more programs,

[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the memory allocation method provided by the embodiment of the present disclosure.

[0018] In a fourth aspect, an embodiment of the present disclosure further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute the memory allocation method provided by an embodiment of the present disclosure.

[0019] The memory allocation scheme provided by the embodiment of the present disclosure creates a first preset number of initial memory pools by starting the memory allocator of the local memory when the application is running, wherein the first preset number is determined at compile time, and creates a second preset number of newly added memory pools by calling the preset parameter sending function to send the first dynamic parameter value, wherein the first dynamic parameter value is used to indicate the newly created memory pool, and the memory allocation of the thread is performed based on the initial memory pool and the newly added memory pool. By adopting the above technical scheme, the concurrency of local memory allocation can be improved, and the memory allocation efficiency can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0021] Figure 1 A flowchart of a memory allocation method provided by an embodiment of the present disclosure;

[0022] Figure 2 A flowchart of another memory allocation method provided by an embodiment of the present disclosure;

[0023] Figure 3 A flowchart of another memory allocation method provided by an embodiment of the present disclosure;

[0024] Figure 4 A flowchart of another memory allocation method provided by an embodiment of the present disclosure;

[0025] Figure 5 A flowchart of another memory allocation method provided by an embodiment of the present disclosure;

[0026] Figure 6 A schematic diagram of the structure of a memory allocation device provided by an embodiment of the present disclosure;

[0027] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0028] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0029] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0030] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0031] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0032] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0033] Figure 1A flow chart of a memory allocation method provided in an embodiment of the present disclosure is provided. The embodiment of the present disclosure is applicable to the situation of memory allocation in a client. The method can be executed by a memory allocation device, which can be implemented in the form of software and / or hardware. Optionally, it can be implemented by an electronic device, which can be a mobile terminal such as a mobile phone, a smart watch, a tablet computer, and a personal digital assistant.

[0034] like Figure 1 As shown, the method includes:

[0035] Step 101: When the application is running, a first preset number of initial memory pools is created by starting a memory allocator of the local memory, wherein the first preset number is determined at compile time.

[0036] The embodiments of the present disclosure do not limit the type of operating system in the electronic device, for example, it may be an Android operating system. For ease of description, the following description will take the Android operating system as an example.

[0037] For Android applications, in addition to the Java memory management in the Android virtual machine, there is also Native memory in the non-Java runtime environment that needs to be managed. For example, when the player plays videos (video playback function), the camera shoots and edits (video shooting and editing function), and images need to be rendered (image rendering function), these functional modules usually do not apply directly from Java memory when applying for memory, but apply for Native memory. The memory allocator commonly used by Native memory is Jemalloc. Jemalloc is a high-performance, multi-threaded and scalable memory allocator that is suitable for various platforms and application scenarios. It has the advantages of reducing memory fragmentation, improving CPU cache utilization and taking advantage of multi-core processors. For Jemalloc, each thread has a local cache (thread cache) to cache allocated and released memory blocks, reducing lock contention between caches and different threads. Jemalloc provides multiple memory pools (Arena, also known as memory management unit, used to manage a set of continuous memory areas) to meet the memory management needs in multi-threaded scenarios. By using multiple memory pools, threads can be distributed among different memory pools, thereby reducing competition for memory access. For memory allocation within the memory pool, local locks are used to protect concurrent access and avoid data contention.

[0038] Exemplarily, the default number of memory pools is determined at compile time and is recorded as the first preset number, which can be understood as the maximum number of default memory pools. For mobile terminals, the first preset number is usually 1 to 2. After the application process is started, the first preset number is read, and during the initialization process after the memory allocator is started, the first preset number of memory pools is created, which is recorded as the initial memory pool.

[0039] Taking the memory allocator Jemalloc as an example, after Jemalloc is enabled, in the initialization process, Arena is created by calling the internal method arena_new, that is, the initial memory pool is created.

[0040] Step 102: Send a first dynamic parameter value by calling a preset parameter sending function to create a second preset number of newly added memory pools, wherein the first dynamic parameter value is used to indicate a newly created memory pool.

[0041] For existing mobile terminals, 1 to 2 memory pools are usually set by default, the concurrency of local memory allocation is not high, and the memory allocation efficiency is not ideal. In the disclosed embodiment, the number of memory pools can be increased when the application is running to reduce multi-thread lock competition, increase memory application concurrency, improve memory allocation efficiency, and reduce the average CPU usage. A method for creating a new memory pool can be to create it by calling a preset parameter sending function to send a first dynamic parameter value. This creation method is not limited by the first preset number that is hard-coded during compilation.

[0042] Exemplarily, taking the memory allocator as Jemalloc as an example, the preset parameter delivery function may be the mallctl function, and the first dynamic parameter value may be arenas.extend or arenas.create. Before executing this step, the process may further include: determining the system version of the current operating system, and determining the first dynamic parameter value as arenas.extend or arenas.create according to the system version.

[0043] Taking arenas.extend as an example, after arenas.extend is issued, the creation of Arena will be triggered through the following path: anrea_extend_ctl->ctl_grow->anrea_init->arena_init_locked->anrea_new, that is, the creation of a new memory pool is realized.

[0044] It should be noted that the creation of the second preset number of newly added memory pools may be centralized or dynamically created in batches, that is, the newly added memory pools are created when they are needed, without any specific limitation.

[0045] Step 103: Allocate memory for threads based on the initial memory pool and the newly added memory pool.

[0046] Exemplarily, when a memory allocation request of a thread is received, a suitable memory pool may be selected from a first preset number of initial memory pools and a second preset number of newly added memory pools to allocate memory to the thread, and the specific selection method is not limited.

[0047] The memory allocation method provided by the embodiment of the present disclosure creates a first preset number of initial memory pools by starting the memory allocator of the local memory when the application is running, wherein the first preset number is determined at compile time, and creates a second preset number of newly added memory pools by calling the preset parameter sending function to send the first dynamic parameter value, wherein the first dynamic parameter value is used to indicate the newly created memory pool, and performs thread memory allocation based on the initial memory pool and the newly added memory pool. By adopting the above technical solution, on the basis of creating a certain number of initial memory pools determined at compile time when the application is running, more memory pools are created by sending dynamic parameters, so that more memory pools can participate in the memory allocation of threads, which can improve the concurrency of local memory allocation, improve memory allocation efficiency, improve application performance, and thus improve user experience.

[0048] Figure 2 This is a flow chart of another memory allocation method provided by an embodiment of the present disclosure. The embodiment of the present disclosure is optimized based on each optional solution in the above embodiment. Specifically, the method includes the following steps:

[0049] Step 201: When the application is running, a first preset number of initial memory pools are created by starting a memory allocator of the local memory.

[0050] Step 202: Send the first dynamic parameter value by calling the preset parameter sending function to create a second preset number of newly added memory pools.

[0051] Step 203: configure a first memory pool identifier for the first newly added memory pool, and establish a corresponding relationship between the first memory pool identifier and a preset dynamic library.

[0052] Exemplarily, in order to facilitate the use of appropriate memory pools for different threads for memory allocation in the later stage, when creating a new memory pool, an identifier for identifying the identity of the new memory pool is configured for the memory pool, which is recorded as a memory pool identifier, for example, a memory pool id. The first new memory pool may be one or more new memory pools in the second preset number of new memory pools created. The memory pool identifier of the first new memory pool is recorded as the first memory pool identifier.

[0053] Exemplarily, the preset dynamic library may include the dynamic library corresponding to the functional module that needs to apply for local memory, such as the dynamic library corresponding to the video playback module, the dynamic library corresponding to the camera module, etc., and may also include the dynamic library corresponding to the virtual machine, etc., which can be set according to actual needs. The specific number of preset dynamic libraries is not limited. When there are multiple preset dynamic libraries, a corresponding first newly added memory pool can be configured for each preset dynamic library, and the second preset number can be set according to the number of preset dynamic libraries. For example, the second preset number is greater than or equal to the number of preset dynamic libraries. The correspondence between the first memory pool identifier and the preset dynamic library can be a one-to-one relationship or a one-to-many relationship. Among them, the corresponding relationship can specifically be a correspondence between the name of the preset dynamic library and the first memory pool identifier.

[0054] Step 204: In response to the target thread created by the preset dynamic library being started, a binding relationship between the target thread and a first memory pool identifier corresponding to the preset dynamic library is established.

[0055] Exemplarily, the preset dynamic library can create one or more threads, recorded as target threads. After detecting that the target thread is started, the corresponding newly added memory pool is bound to the target thread, that is, a binding relationship is established between the target thread and the first memory pool identifier corresponding to the preset dynamic library to which the target thread belongs.

[0056] For example, there is a corresponding relationship between the preset dynamic library A and the first memory pool identifier a. When the preset dynamic library A creates the target thread 1, after the target thread 1 is started, a binding relationship between the target thread 1 and the first memory pool identifier a is established. Subsequently, if the preset dynamic library A creates the target thread 2, after the target thread 2 is started, a binding relationship between the target thread 2 and the first memory pool identifier a is established.

[0057] Optionally, this step may specifically include: detecting that the target thread created by the preset dynamic library calls a thread naming function, issuing a second dynamic parameter value by calling the preset parameter issuing function, and establishing a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library, wherein the second dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the first memory pool identifier corresponding to the preset dynamic library. In this way, the start of the target thread can be accurately detected without relying on the source code environment, that is, without knowing the source code of the system library, and the establishment of the binding relationship can be completed within the target thread.

[0058] Exemplarily, a hook function may be used to detect the call of a thread naming function, such as pthread_setname_np. The parameter value for indicating the binding of a thread and a memory pool may be thread.arena. The mallctl function sends thread.arena and the memory pool ID to be bound, thereby implementing the binding of the current target thread and the memory pool ID.

[0059] Step 205: Allocate memory for the thread based on the initial memory pool and the newly added memory pool.

[0060] This step may include: in response to a memory allocation request of the target thread, allocating memory for the target thread based on a first newly added memory pool to which a first memory pool identifier having a binding relationship with the target thread belongs.

[0061] Exemplarily, for a target thread that has established a binding relationship, when the target thread needs to apply for memory, the memory allocation request of the target thread can be responded to, the first newly added memory pool to which the current target thread is bound can be determined, and memory allocation can be performed based on the first newly added memory pool bound to the target thread. As in the above example, when target thread 1 or target thread 2 applies for memory, memory allocation for target thread 1 or target thread 2 can be performed based on the first newly added memory pool to which the first memory pool identifier a belongs. It can be seen that threads created by the same preset dynamic library will be bound to the same newly added memory pool, that is, threads created by the same preset dynamic library apply for memory from the same newly added memory pool.

[0062] Optionally, this step may further include: in response to a memory allocation request of the first thread, when it is determined that the first thread is not bound to any of the newly added memory pools, allocating memory for the first thread based on the initial memory pool. Thus, it can be ensured that the memory allocation request of the unbound thread can be responded to in a timely and accurate manner based on the initial memory pool, so that the memory requested by each thread is more reasonably distributed in each memory pool.

[0063] The memory allocation method provided by the embodiment of the present disclosure configures a memory pool identifier for the newly added memory pool after creating a new memory pool, and establishes a corresponding relationship between a preset dynamic library and the memory pool identifier; after the thread created by the preset dynamic library is started, a binding relationship between the thread and the newly added memory pool is established, thereby using the preset dynamic library as a division dimension, concentrating the memory allocation needs of threads created by the same preset dynamic library into the same newly added memory pool, and making the distribution of memory applied for by each thread in each memory pool more reasonable.

[0064] Figure 3 This is a flow chart of another memory allocation method provided by an embodiment of the present disclosure. The embodiment of the present disclosure is optimized based on each optional solution in the above embodiment. Specifically, the method includes the following steps:

[0065] Step 301: When the application is running, a first preset number of initial memory pools are created by starting a memory allocator of the local memory.

[0066] Step 302: Send the first dynamic parameter value by calling the preset parameter sending function to create a second preset number of newly added memory pools.

[0067] Step 303: configure a second memory pool identifier for the second newly added memory pool, and establish a corresponding relationship between the second memory pool identifier and a preset thread.

[0068] The second newly added memory pool may be one or more newly added memory pools in the created second preset number of newly added memory pools. The memory pool identifier of the second newly added memory pool is recorded as the second memory pool identifier.

[0069] Exemplarily, the preset threads may include threads with longer running time, that is, threads with running time greater than a preset time threshold during the running of the application, such as rendering threads. During the running of the application, the rendering thread needs to render data to realize page display, so an independent new memory pool can be set for the rendering thread. The corresponding relationship between the second memory pool identifier and the preset thread can be a one-to-one relationship or a one-to-many relationship.

[0070] Step 304: In response to the preset thread being started, a binding relationship between the preset thread and a second memory pool identifier corresponding to the preset thread is established.

[0071] Optionally, this step may specifically include: in response to the preset thread calling the data rendering function, issuing a third dynamic parameter value by calling the preset parameter issuing function, establishing a binding relationship between the preset thread and the second memory pool identifier corresponding to the preset thread, wherein the third dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the second memory pool identifier corresponding to the preset thread. In this way, the startup of the preset thread can be accurately detected without relying on the source code environment, that is, without knowing the source code of the system library, and the establishment of the binding relationship can be completed within the preset thread.

[0072] Exemplarily, a hook function may be used to detect the call of a data rendering function, such as eglSwapBuffersWithDamageKHR. The parameter value for indicating the binding of a thread and a memory pool may be thread.arena. The mallctl function sends thread.arena and the memory pool id to be bound, thereby implementing the binding of a preset thread and a memory pool id.

[0073] Step 305: Allocate memory for the thread based on the initial memory pool and the newly added memory pool.

[0074] This step may include: in response to a memory allocation request of the preset thread, allocating memory to the preset thread based on a second newly added memory pool to which a second memory pool identifier having a binding relationship with the preset thread belongs.

[0075] Exemplarily, for a preset thread that has established a binding relationship, when the preset thread needs to apply for memory, the memory allocation request of the preset thread can be responded to, the second newly added memory pool to which the current preset thread is bound can be determined, and memory allocation can be performed based on the bound second newly added memory pool. As in the above example, when the rendering thread applies for memory, the memory allocation of the rendering thread can be performed based on the second newly added memory pool to which the rendering thread belongs. It can be seen that the memory application of the same preset thread with a longer running time can be handled by the bound newly added memory pool.

[0076] Optionally, this step may further include: in response to a memory allocation request of the first thread, when it is determined that the first thread is not bound to any of the newly added memory pools, allocating memory for the first thread based on the initial memory pool. Thus, it can be ensured that the memory allocation request of the unbound thread can be responded to in a timely and accurate manner based on the initial memory pool, so that the memory requested by each thread is more reasonably distributed in each memory pool.

[0077] The memory allocation method provided by the embodiment of the present disclosure configures a memory pool identifier for the newly added memory pool after creating a new memory pool, and establishes a corresponding relationship between a preset thread and the memory pool identifier. After the preset thread is started, a binding relationship between the preset thread and the newly added memory pool is established, so that the memory application of the same preset thread with a longer running time is processed by the bound newly added memory pool, so that the distribution of the memory applied by each thread in each memory pool is more reasonable.

[0078] Optionally, in the case where the preset thread is a rendering thread, since the rendering thread is created earlier after the application is started, the establishment of the newly added memory pool corresponding to the rendering thread and the binding with the memory pool identifier can be completed after the preset thread is started. For example, in response to the preset thread calling the data rendering function, the first dynamic parameter value is sent by calling the preset parameter sending function, the newly added memory pool corresponding to the preset thread is created, and the second memory pool identifier is configured for the newly added memory pool corresponding to the preset thread, and the third dynamic parameter value is sent by calling the preset parameter sending function to establish a binding relationship between the preset thread and the second memory pool identifier corresponding to the preset thread.

[0079] Figure 4This is a flow chart of another memory allocation method provided by an embodiment of the present disclosure. The embodiment of the present disclosure is optimized based on each optional solution in the above embodiment. Specifically, the method includes the following steps:

[0080] Step 401: When the application is running, a first preset number of initial memory pools are created by starting a memory allocator of the local memory.

[0081] Step 402: Send the first dynamic parameter value by calling the preset parameter sending function to create a second preset number of newly added memory pools.

[0082] Optionally, the second preset number may be determined according to the sum of the number of preset dynamic libraries and the number of preset threads.

[0083] Step 403: configure a first memory pool identifier for the first newly added memory pool, and establish a corresponding relationship between the first memory pool identifier and a preset dynamic library; configure a second memory pool identifier for the second newly added memory pool, and establish a corresponding relationship between the second memory pool identifier and a preset thread.

[0084] Step 404: In response to the preset thread calling the data rendering function, a third dynamic parameter value is issued by calling the preset parameter issuing function, and a binding relationship between the preset thread and the second memory pool identifier corresponding to the preset thread is established.

[0085] Step 405: In response to the memory allocation request of the preset thread, memory allocation for the preset thread is performed based on the second newly added memory pool to which the second memory pool identifier having a binding relationship with the preset thread belongs.

[0086] Step 406: Detect that the target thread created by the preset dynamic library calls the thread naming function, issue the second dynamic parameter value by calling the preset parameter issuing function, and establish a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library.

[0087] Step 407: In response to the memory allocation request of the target thread, memory allocation is performed for the target thread based on the first newly added memory pool to which the first memory pool identifier having a binding relationship with the target thread belongs.

[0088] Step 408: In response to the memory allocation request of the first thread, if it is determined that the first thread is not bound to any of the newly added memory pools, memory allocation for the first thread is performed based on the initial memory pool.

[0089] In the disclosed embodiment, a correspondence between a preset dynamic library and a memory pool identifier is established, and a correspondence between a preset thread and a memory pool identifier is also established, thereby achieving two different modes of binding threads and memory pools to coexist, making the distribution of memory requested by each thread in each memory pool more reasonable.

[0090] Figure 5 This is a flow chart of another memory allocation method provided by an embodiment of the present disclosure. The embodiment of the present disclosure is optimized based on each optional solution in the above embodiment. Specifically, the method includes the following steps:

[0091] Step 501: When the application is running, a first preset number of initial memory pools are created by starting a memory allocator of the local memory.

[0092] Step 502: Send the first dynamic parameter value by calling the preset parameter sending function to create a second preset number of newly added memory pools.

[0093] Step 503: Use the dynamic loading function to obtain the address of the memory pool quantity variable, and modify the original variable value in the address to the target variable value, wherein the original variable value is determined according to the first preset quantity, and the target variable value is determined according to the sum of the first preset quantity and the second preset quantity.

[0094] Exemplarily, the dynamic loading function may be a dlsym function, the variable for the number of memory pools may be narenas_auto, and the corresponding variable value may be je_narenas_auto. The dynamic loading function may be used to accurately obtain the address of the variable for the number of memory pools, and to safely modify the original variable value to the target variable value. The original variable value is a read-only value after the memory allocator is initialized. By modifying it in the above manner, the number of memory pools after the newly added memory pool is created may be safely modified, so that the subsequent memory request of the thread may be allocated to the newly added memory pool instead of just to the initialized memory pool.

[0095] Step 504: In response to the memory allocation request of the second thread, based on the variable value of the current memory pool quantity variable, poll the initial memory pool and the newly added memory pool to find the target memory pool with the least number of currently mounted threads from the initial memory pool and the newly added memory pool, and perform memory allocation for the second thread based on the target memory pool.

[0096] Exemplarily, when the second thread applies for memory, it can poll the currently created initial memory pool and the newly added memory pool based on the variable value of the current memory pool quantity variable, that is, the modified target variable value, and find the target memory pool with the least number of currently mounted threads, and allocate memory for the second thread based on the target memory pool. At different times, the target memory pool may be the initial memory pool or the newly added memory pool. Through the above dynamic allocation method, the balance of memory allocation in each memory pool can be guaranteed.

[0097] The memory allocation method provided by the embodiment of the present disclosure creates more memory pools by dynamically issuing parameters on the basis of a certain number of initial memory pools determined at compile time when the application is running, so that more memory pools can participate in the memory allocation of threads, which can improve the concurrency of local memory allocation and the memory allocation efficiency. The variable value of the memory pool quantity variable can be safely modified by using a dynamic loading function. By dynamically allocating memory pools for the memory application of threads, the association between memory pools and threads can be automatically completed, thereby further improving the memory allocation efficiency.

[0098] Figure 6 A schematic diagram of the structure of a memory allocation device provided by an embodiment of the present disclosure is shown in FIG. Figure 6 As shown, the device comprises:

[0099] An initial memory pool creation module 601 is used to create a first preset number of initial memory pools by starting a memory allocator of a local memory when the application is running, wherein the first preset number is determined at compile time;

[0100] A new memory pool creation module 602 is used to create a second preset number of new memory pools by issuing a first dynamic parameter value by calling a preset parameter issuing function, wherein the first dynamic parameter value is used to indicate a new memory pool;

[0101] The memory allocation module 603 is used to allocate memory for threads based on the initial memory pool and the newly added memory pool.

[0102] The memory allocation device provided by the embodiment of the present disclosure creates a first preset number of initial memory pools by starting the memory allocator of the local memory when the application is running, wherein the first preset number is determined at compile time, and creates a second preset number of newly added memory pools by calling the preset parameter sending function to send the first dynamic parameter value, wherein the first dynamic parameter value is used to indicate the newly created memory pool, and performs thread memory allocation based on the initial memory pool and the newly added memory pool. By adopting the above technical solution, on the basis of creating a certain number of initial memory pools determined at compile time when the application is running, more memory pools are created by sending dynamic parameters, so that more memory pools can participate in the memory allocation of threads, which can improve the concurrency of local memory allocation and improve memory allocation efficiency.

[0103] Optionally, the device further comprises:

[0104] A first correspondence establishing module, configured to configure a first memory pool identifier for the first newly added memory pool and establish a correspondence between the first memory pool identifier and a preset dynamic library after the first dynamic parameter value is issued by calling the preset parameter issuing function and a second preset number of newly added memory pools are created;

[0105] A first binding relationship establishing module is used for establishing a binding relationship between the target thread and a first memory pool identifier corresponding to the preset dynamic library in response to the start of a target thread created by the preset dynamic library before memory allocation of the thread is performed based on the initial memory pool and the newly added memory pool;

[0106] Wherein, the memory allocation module includes:

[0107] The first allocation unit is configured to respond to a memory allocation request of the target thread and allocate memory to the target thread based on a first newly added memory pool to which a first memory pool identifier having a binding relationship with the target thread belongs.

[0108] Optionally, the first binding relationship establishing module is specifically used to: detect that the target thread created by the preset dynamic library calls a thread naming function, and issue a second dynamic parameter value by calling the preset parameter issuing function to establish a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library, wherein the second dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the first memory pool identifier corresponding to the preset dynamic library.

[0109] Optionally, the device further comprises:

[0110] A second correspondence establishing module, configured to configure a second memory pool identifier for a second newly added memory pool and establish a correspondence between the second memory pool identifier and a preset thread after the first dynamic parameter value is issued by calling the preset parameter issuing function to create a second preset number of newly added memory pools;

[0111] A second binding relationship establishing module is used for establishing a binding relationship between the preset thread and a second memory pool identifier corresponding to the preset thread in response to the preset thread starting before the memory allocation of the thread is performed based on the initial memory pool and the newly added memory pool;

[0112] Wherein, the memory allocation module includes:

[0113] A second allocation unit is configured to respond to a memory allocation request of the preset thread and allocate memory to the preset thread based on a second newly added memory pool to which a second memory pool identifier having a binding relationship with the preset thread belongs.

[0114] Optionally, the preset thread includes a rendering thread; wherein the second binding relationship establishing module is specifically used to: in response to the preset thread calling the data rendering function, issue a third dynamic parameter value by calling the preset parameter sending function, and establish a binding relationship between the preset thread and the second memory pool identifier corresponding to the preset thread, wherein the third dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the second memory pool identifier corresponding to the preset thread.

[0115] Optional, memory allocation module, including:

[0116] The third allocation unit is configured to respond to a memory allocation request of the first thread and allocate memory for the first thread based on the initial memory pool when it is determined that the first thread is not bound to any of the newly added memory pools.

[0117] Optionally, the device further comprises:

[0118] a variable value modification module, configured to issue a first dynamic parameter value by calling a preset parameter issuing function, and after creating a second preset number of newly added memory pools, obtain an address of a memory pool quantity variable by using a dynamic loading function, and modify an original variable value in the address to a target variable value, wherein the original variable value is determined according to the first preset number, and the target variable value is determined according to the sum of the first preset number and the second preset number;

[0119] Wherein, the memory allocation module includes:

[0120] A fourth allocation unit is used to respond to the memory allocation request of the second thread, poll the initial memory pool and the newly added memory pool based on the variable value of the current memory pool quantity variable, so as to find the target memory pool with the least number of currently mounted threads from the initial memory pool and the newly added memory pool, and perform memory allocation for the second thread based on the target memory pool.

[0121] The memory allocation device provided in the embodiments of the present disclosure can execute the memory allocation method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.

[0122] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present disclosure.

[0123] Figure 7 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. Figure 7, which shows an electronic device (eg, Figure 7 The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0124] like Figure 7 As shown, the electronic device 700 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An edit / output (I / O) interface 705 is also connected to the bus 704.

[0125] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 7 The electronic device 700 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0126] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 709, or installed from a storage device 708, or installed from a ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0127] The electronic device provided by the embodiment of the present disclosure and the memory allocation method provided by the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.

[0128] An embodiment of the present disclosure provides a computer storage medium on which a computer program is stored. When the program is executed by a processor, the memory allocation method provided in the above embodiment is implemented.

[0129] An embodiment of the present disclosure provides a computer program product, including a computer program, which implements the memory allocation method provided in the above embodiment when executed by a processor.

[0130] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0131] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0132] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: creates a first preset number of initial memory pools by starting the memory allocator of the local memory when the application is running, wherein the first preset number is determined at compile time; creates a second preset number of newly added memory pools by calling a preset parameter sending function to send a first dynamic parameter value, wherein the first dynamic parameter value is used to indicate a newly created memory pool; and performs memory allocation for threads based on the initial memory pool and the newly added memory pool.

[0133] Computer program code for performing operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may execute entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server.

[0134] The flow chart and block diagram in the accompanying drawings illustrate the possible functions and operations of the method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the module, the program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0135] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, a memory allocation module may also be described as a "module for allocating memory for threads based on the initial memory pool and the newly added memory pool".

[0136] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0137] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0138] According to one or more embodiments of the present disclosure, a memory allocation method is provided, comprising:

[0139] When the application is running, a first preset number of initial memory pools is created by starting a memory allocator of the local memory, wherein the first preset number is determined at compile time;

[0140] Creating a second preset number of newly added memory pools by calling a preset parameter sending function to send a first dynamic parameter value, wherein the first dynamic parameter value is used to indicate a newly created memory pool;

[0141] Memory allocation for threads is performed based on the initial memory pool and the newly added memory pool.

[0142] According to one or more embodiments of the present disclosure, after issuing the first dynamic parameter value by calling the preset parameter issuing function and creating a second preset number of newly added memory pools, the method further includes:

[0143] Configuring a first memory pool identifier for the first newly added memory pool, and establishing a corresponding relationship between the first memory pool identifier and a preset dynamic library;

[0144] Before allocating memory for threads based on the initial memory pool and the newly added memory pool, the method further includes:

[0145] In response to the target thread created by the preset dynamic library being started, a binding relationship between the target thread and a first memory pool identifier corresponding to the preset dynamic library is established;

[0146] The memory allocation of threads based on the initial memory pool and the newly added memory pool includes:

[0147] In response to the memory allocation request of the target thread, memory allocation of the target thread is performed based on a first newly added memory pool to which a first memory pool identifier having a binding relationship with the target thread belongs.

[0148] According to one or more embodiments of the present disclosure, the starting of the target thread created by the preset dynamic library and establishing a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library include:

[0149] It is detected that the target thread created by the preset dynamic library calls a thread naming function, and a second dynamic parameter value is issued by calling the preset parameter issuing function to establish a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library, wherein the second dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the first memory pool identifier corresponding to the preset dynamic library.

[0150] According to one or more embodiments of the present disclosure, after issuing the first dynamic parameter value by calling the preset parameter issuing function and creating a second preset number of newly added memory pools, the method further includes:

[0151] Configuring a second memory pool identifier for the second newly added memory pool, and establishing a corresponding relationship between the second memory pool identifier and a preset thread;

[0152] Before allocating memory for threads based on the initial memory pool and the newly added memory pool, the method further includes:

[0153] In response to the preset thread being started, establishing a binding relationship between the preset thread and a second memory pool identifier corresponding to the preset thread;

[0154] The memory allocation of threads based on the initial memory pool and the newly added memory pool includes:

[0155] In response to the memory allocation request of the preset thread, memory allocation for the preset thread is performed based on a second newly added memory pool to which a second memory pool identifier having a binding relationship with the preset thread belongs.

[0156] According to one or more embodiments of the present disclosure, the preset thread includes a rendering thread;

[0157] The step of establishing a binding relationship between the preset thread and a second memory pool identifier corresponding to the preset thread in response to the preset thread starting includes:

[0158] In response to the preset thread calling the data rendering function, a third dynamic parameter value is issued by calling the preset parameter issuing function to establish a binding relationship between the preset thread and the second memory pool identifier corresponding to the preset thread, wherein the third dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the second memory pool identifier corresponding to the preset thread.

[0159] According to one or more embodiments of the present disclosure, the memory allocation of threads based on the initial memory pool and the newly added memory pool includes:

[0160] In response to a memory allocation request of a first thread, when it is determined that the first thread is not bound to any of the newly added memory pools, memory allocation for the first thread is performed based on the initial memory pool.

[0161] According to one or more embodiments of the present disclosure, after issuing the first dynamic parameter value by calling the preset parameter issuing function and creating a second preset number of newly added memory pools, the method further includes:

[0162] Using a dynamic loading function to obtain an address of a memory pool quantity variable, and modifying an original variable value in the address to a target variable value, wherein the original variable value is determined according to the first preset quantity, and the target variable value is determined according to the sum of the first preset quantity and the second preset quantity;

[0163] The memory allocation of threads based on the initial memory pool and the newly added memory pool includes:

[0164] In response to the memory allocation request of the second thread, based on the variable value of the current memory pool quantity variable, poll the initial memory pool and the newly added memory pool to find the target memory pool with the least number of currently mounted threads from the initial memory pool and the newly added memory pool, and perform memory allocation for the second thread based on the target memory pool.

[0165] According to one or more embodiments of the present disclosure, a memory allocation device is provided, comprising:

[0166] An initial memory pool creation module, used to create a first preset number of initial memory pools by starting a memory allocator of a local memory when the application is running, wherein the first preset number is determined at compile time;

[0167] A newly added memory pool creation module is used to issue a first dynamic parameter value by calling a preset parameter issuing function to create a second preset number of newly added memory pools, wherein the first dynamic parameter value is used to indicate a newly created memory pool;

[0168] A memory allocation module is used to allocate memory for threads based on the initial memory pool and the newly added memory pool.

[0169] According to one or more embodiments of the present disclosure, an electronic device is provided, the electronic device comprising:

[0170] one or more processors;

[0171] a storage device for storing one or more programs,

[0172] When the one or more programs are executed by the one or more processors, the one or more processors implement the memory allocation method provided by the embodiment of the present disclosure.

[0173] According to one or more embodiments of the present disclosure, a storage medium containing computer executable instructions is provided. When the computer executable instructions are executed by a computer processor, they are used to execute the memory allocation method provided by the embodiments of the present disclosure.

[0174] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.

[0175] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0176] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A memory allocation method, characterized in that: include: When the application is running, a first preset number of initial memory pools is created by starting a memory allocator of the local memory, wherein the first preset number is determined at compile time; Creating a second preset number of newly added memory pools by calling a preset parameter sending function to send a first dynamic parameter value, wherein the first dynamic parameter value is used to indicate a newly created memory pool; Memory allocation for threads is performed based on the initial memory pool and the newly added memory pool.

2. The method according to claim 1, characterized in that: After issuing the first dynamic parameter value by calling the preset parameter issuing function and creating a second preset number of newly added memory pools, the method further includes: Configuring a first memory pool identifier for the first newly added memory pool, and establishing a corresponding relationship between the first memory pool identifier and a preset dynamic library; Before allocating memory for threads based on the initial memory pool and the newly added memory pool, the method further includes: In response to the target thread created by the preset dynamic library being started, a binding relationship between the target thread and a first memory pool identifier corresponding to the preset dynamic library is established; The memory allocation of threads based on the initial memory pool and the newly added memory pool includes: In response to the memory allocation request of the target thread, memory allocation of the target thread is performed based on a first newly added memory pool to which a first memory pool identifier having a binding relationship with the target thread belongs.

3. The method according to claim 2, characterized in that The starting of the target thread created in response to the preset dynamic library and establishing a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library include: It is detected that the target thread created by the preset dynamic library calls a thread naming function, and a second dynamic parameter value is issued by calling the preset parameter issuing function to establish a binding relationship between the target thread and the first memory pool identifier corresponding to the preset dynamic library, wherein the second dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the first memory pool identifier corresponding to the preset dynamic library.

4. The method according to claim 1, characterized in that: After issuing the first dynamic parameter value by calling the preset parameter issuing function and creating a second preset number of newly added memory pools, the method further includes: Configuring a second memory pool identifier for the second newly added memory pool, and establishing a corresponding relationship between the second memory pool identifier and a preset thread; Before allocating memory for threads based on the initial memory pool and the newly added memory pool, the method further includes: In response to the preset thread being started, establishing a binding relationship between the preset thread and a second memory pool identifier corresponding to the preset thread; The memory allocation of threads based on the initial memory pool and the newly added memory pool includes: In response to the memory allocation request of the preset thread, memory allocation for the preset thread is performed based on a second newly added memory pool to which a second memory pool identifier having a binding relationship with the preset thread belongs.

5. The method according to claim 4, characterized in that The preset thread includes a rendering thread; The step of establishing a binding relationship between the preset thread and a second memory pool identifier corresponding to the preset thread in response to the preset thread starting includes: In response to the preset thread calling the data rendering function, a third dynamic parameter value is issued by calling the preset parameter issuing function to establish a binding relationship between the preset thread and the second memory pool identifier corresponding to the preset thread, wherein the third dynamic parameter value includes a parameter value for indicating the binding thread and the memory pool, and the second memory pool identifier corresponding to the preset thread.

6. The method according to any one of claims 2 to 5, characterized in that: The performing memory allocation of threads based on the initial memory pool and the newly added memory pool includes: In response to a memory allocation request of a first thread, when it is determined that the first thread is not bound to any of the newly added memory pools, memory allocation for the first thread is performed based on the initial memory pool.

7. The method according to claim 1, characterized in that After issuing the first dynamic parameter value by calling the preset parameter issuing function and creating a second preset number of newly added memory pools, the method further includes: Using a dynamic loading function to obtain an address of a memory pool quantity variable, and modifying an original variable value in the address to a target variable value, wherein the original variable value is determined according to the first preset quantity, and the target variable value is determined according to the sum of the first preset quantity and the second preset quantity; The memory allocation of threads based on the initial memory pool and the newly added memory pool includes: In response to the memory allocation request of the second thread, based on the variable value of the current memory pool quantity variable, poll the initial memory pool and the newly added memory pool to find the target memory pool with the least number of currently mounted threads from the initial memory pool and the newly added memory pool, and perform memory allocation for the second thread based on the target memory pool.

8. A memory allocation device, characterized in that: include: An initial memory pool creation module, used to create a first preset number of initial memory pools by starting a memory allocator of a local memory when the application is running, wherein the first preset number is determined at compile time; A newly added memory pool creation module is used to issue a first dynamic parameter value by calling a preset parameter issuing function to create a second preset number of newly added memory pools, wherein the first dynamic parameter value is used to indicate a newly created memory pool; A memory allocation module is used to allocate memory for threads based on the initial memory pool and the newly added memory pool.

9. An electronic device, characterized in that: The electronic device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the memory allocation method as described in any one of claims 1-7.

10. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the memory allocation method as described in any one of claims 1 to 7 when executed by a computer processor.