Memory allocation method and device, electronic equipment and storage medium

The thread local allocation buffer expansion function determines the heap memory status, allocates free memory of the virtual machine and sets the amount of memory, solves the memory problems caused by Java memory leaks and irregular codes, avoids application crashes, and improves user experience.

CN120295749APending Publication Date: 2025-07-11BEIJING ZITIAO NETWORK TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410045691.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-11
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

In the prior art, the memory shortage caused by Java memory leaks and Java code writing is difficult to fundamentally solve from the source, resulting in application crashes.

Method used

Determine the available heap memory status through the thread local allocation buffer expansion function, allocate free memory of the virtual machine, and set the allocated and freed memory amounts to expand the heap memory limit to avoid insufficient memory.

Benefits of technology

Reduces the probability of application crash caused by insufficient memory and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120295749A_ABST
    Figure CN120295749A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a memory allocation method and device, electronic equipment and a storage medium. The memory allocation method comprises the steps that state information of available heap memories is determined through a thread local allocation buffer area expansion function; under the condition that the state information is in a to-be-expanded state, allocating an idle memory corresponding to the virtual machine; setting the allocated memory amount corresponding to the free memory as a first numerical value; and setting the released memory amount corresponding to the free memory as a second numerical value. The memory allocation method reduces the problem of application crash caused by insufficient memory. By judging the state information of the available heap memory, whether the idle memory corresponding to the virtual machine is allocated or not is determined, so that memory expansion is realized, and the problem of application crash caused by insufficient memory is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to computer technology, and more particularly to a memory allocation method, device, electronic device, and storage medium. Background Art

[0002] An application project is a software project developed to achieve a specific function or goal. In application projects, insufficient memory problems often occur due to Java memory leaks or improper Java code writing. For such problems, it is often difficult to fundamentally solve the problem from the source. Therefore, how to reduce the problem of application crashes caused by insufficient memory is a technical problem that needs to be solved urgently. Summary of the invention

[0003] The present disclosure provides a memory allocation method, device, electronic device and storage medium to reduce the problem of application crash caused by insufficient memory.

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

[0005] Determine the status information of available heap memory through the thread local allocation buffer expansion function;

[0006] When the state information is a state to be expanded, allocating free memory corresponding to the virtual machine;

[0007] Setting the amount of allocated memory corresponding to the free memory to a first value;

[0008] The amount of released memory corresponding to the free memory is set to a second value.

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

[0010] A determination module, used to determine the status information of available heap memory through a thread-local allocation buffer expansion function;

[0011] An allocation module, configured to allocate free memory corresponding to the virtual machine when the state information is in a state to be expanded;

[0012] A first setting module, used to set the amount of allocated memory corresponding to the free memory to a first value;

[0013] The second setting module is used to set the amount of released memory corresponding to the free memory to a second value.

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

[0015] one or more processing devices;

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

[0017] When the one or more programs are executed by the one or more processing devices, the one or more processing devices implement a memory allocation method provided in an embodiment of the present disclosure.

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

[0019] In the embodiment of the present disclosure, the status information of the available heap memory is determined through a thread-local allocation buffer expansion function; in the case where the status information is in a state to be expanded, free memory corresponding to the virtual machine is allocated; the allocated memory amount corresponding to the free memory is set to a first value; the released memory amount corresponding to the free memory is set to a second value. The problem of application crashes caused by memory shortage is reduced. By judging the status information of the available heap memory, it is determined whether to allocate free memory corresponding to the virtual machine to implement memory expansion and avoid the problem of application crashes caused by memory shortage. Description of the Drawings

[0020] Combined with the drawings and with reference to the following specific embodiments, the above and other features, advantages and aspects of the various embodiments of the present disclosure will become more obvious. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic and the original elements and elements are not necessarily drawn to scale.

[0021] Figure 1 It is a flowchart of a memory allocation method provided in an embodiment of the present disclosure;

[0022] Figure 2 It is a flowchart of another memory allocation method provided in an embodiment of the present disclosure;

[0023] Figure 3 It is a structural diagram of a memory allocation device provided in an embodiment of the present disclosure;

[0024] Figure 4 It is a structural diagram of an electronic device provided in an embodiment of the present disclosure. Detailed Embodiments

[0025] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.

[0026] It should be understood that the various steps recited in the method embodiments of the present disclosure can be executed in a different order 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 regard.

[0027] As used herein, the term "including" and its variants are open-ended, i.e., "including but not limited to". The term "based on" means "at least partially based 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.

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

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

[0030] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only for illustrative purposes and are not used to limit the scope of these messages or information.

[0031] Figure 1 is a schematic flowchart of a memory allocation method provided by an embodiment of the present disclosure. The embodiment of the present disclosure is applicable to the situation of memory allocation. This method can be executed by a memory allocation device, and this device can be implemented in the form of software and / or hardware. Optionally, it can be implemented by an electronic device, and this electronic device can be a mobile terminal, a PC or a server, etc.

[0032] As Figure 1 shown, the method includes:

[0033] S110. Determine the status information of the available heap memory through the thread local allocation buffer expansion function.

[0034] The thread-local allocation buffer expansion function can be regarded as an expansion function executed during memory allocation, such as the AllocWithNewTLAB function. The available heap memory can be regarded as the available heap memory. The heap memory can be regarded as a dynamically allocated memory area that can be used to store objects, data structures, or dynamically allocated memory blocks created by the program during runtime.

[0035] The status information can be regarded as information characterizing the status of the available heap memory, such as the status indicating whether the available heap memory is insufficient.

[0036] In this embodiment, the status information of the available heap memory can be determined through the thread-local allocation buffer expansion function to determine whether the available heap memory is insufficient. The determination means is not limited. For example, the hook technology can be used to determine the status information of the available heap memory in the thread-local allocation buffer expansion function.

[0037] In one embodiment, determining the status information of the available heap memory through the thread-local allocation buffer expansion function includes:

[0038] Judging whether the available heap memory is less than a set threshold through the thread-local allocation buffer expansion function;

[0039] If so, set the status information of the available heap memory to the to-be-expanded state.

[0040] The set threshold can be a threshold preset for determining whether the available heap memory is insufficient. The value of the set threshold is not limited here and can be set according to the actual situation. The to-be-expanded state can be regarded as the state to be expanded. When in the to-be-expanded state, the memory can be expanded.

[0041] In this embodiment, it can be determined in the thread-local allocation buffer expansion function whether the available heap memory is less than the set threshold. If the available heap memory is less than the set threshold, it can be considered that the available heap memory is insufficient, and then the status information of the available heap memory can be set to the to-be-expanded state to facilitate memory expansion.

[0042] S120. When the status information is in the to-be-expanded state, allocate the idle memory corresponding to the virtual machine.

[0043] When the status information is in the to-be-expanded state, expansion can be achieved by allocating the idle memory corresponding to the virtual machine. The idle memory corresponding to the virtual machine can be the idle memory corresponding to the virtual machine, such as the non-moving space.

[0044] When allocating the idle memory corresponding to the virtual machine in this embodiment, the allocation of the idle memory can be achieved by setting the memory allocation function to achieve the expansion of the heap memory. The memory allocation function can be the function of the virtual machine that implements memory allocation.

[0045] S130. Set the allocated memory amount corresponding to the free memory to a first value.

[0046] The allocated memory amount can be considered as the amount of memory that has been allocated. The first value can be considered as a preset value representing the amount of memory allocated from the free memory.

[0047] In this operation, setting the allocated memory amount corresponding to the free memory to the first value can avoid reaching the heap memory limit, thereby causing a memory overflow. The value of the first value is not limited. It can be zero or a value whose difference from zero is less than a set value, as long as it is ensured that the set first value does not cause the heap memory limit to be reached.

[0048] S140. Set the released memory amount corresponding to the free memory to a second value.

[0049] The released memory amount can be considered as the amount of memory that has been released, such as the amount of memory released in the allocated free memory. The second value can be considered as a preset value representing the amount of memory released from the allocated free memory.

[0050] This operation sets the released memory amount corresponding to the free memory to the second value to be associated with setting the allocated memory amount to the first value, avoiding reaching the heap memory limit, thereby causing a memory overflow. The value of the second value is not limited. It can be zero or a value whose difference from zero is less than a set value, as long as it is ensured that the set second value is associated with the first value and does not cause the heap memory limit to be reached or an error to occur.

[0051] The technical solution of the embodiment of the present disclosure determines the status information of the available heap memory through the thread local allocation buffer expansion function; in the case where the status information is in a state to be expanded, allocate the free memory corresponding to the virtual machine; set the allocated memory amount corresponding to the free memory to the first value; set the released memory amount corresponding to the free memory to the second value. Reduce the problem of application crashes caused by insufficient memory. By judging the status information of the available heap memory, it is determined whether to allocate the free memory corresponding to the virtual machine to achieve memory expansion and avoid the problem of application crashes caused by insufficient memory.

[0052] Figure 2 It is a schematic flowchart of another memory allocation method provided by the embodiment of the present disclosure. This embodiment details the operation of allocating free memory. Refer to Figure 2 , the memory allocation method includes the following steps:

[0053] S210. Determine the status information of the available heap memory through the thread local allocation buffer expansion function.

[0054] S220. When the status information is in the state of waiting for expansion, set the allocator type of the memory allocation function to a non-movable object type, where the non-movable object type is the type corresponding to the free memory.

[0055] An allocator is an object or function used to manage dynamic memory allocation. It is responsible for allocating and releasing memory blocks for program use. The allocator type can be a parameter used to set the type in the memory allocation function. By setting the allocator type, non-movable space can be triggered to allocate memory, realizing heap memory expansion and avoiding memory shortage.

[0056] This operation sets the allocator type of the memory allocation function to a non-movable object type, where the non-movable object type is the type corresponding to the free memory, triggering non-movable space to allocate memory and realizing heap memory expansion.

[0057] S230. Set the allocated memory amount corresponding to the free memory to a first value.

[0058] S240. Set the released memory amount corresponding to the free memory to a second value.

[0059] This embodiment refines the scheme for allocating free memory. In this embodiment, by setting the allocator type of the memory allocation function to a non-movable object type, non-movable space is triggered to allocate memory, realizing heap memory expansion.

[0060] Based on the above embodiment, a variant embodiment of the above embodiment is proposed. Here, it should be noted that for the sake of brief description, only the differences from the above embodiment are described in the variant embodiment.

[0061] In one embodiment, the setting the allocator type of the memory allocation function to a non-movable object type includes:

[0062] Call the memory allocation function of the virtual machine and set the allocator type of the memory allocation function to a non-movable object type.

[0063] In this embodiment, when setting the allocator type, call the memory allocation function of the virtual machine, and then set the allocator type by setting the allocator type of the memory allocation function to a non-movable object type.

[0064] In one embodiment, the setting the allocated memory amount corresponding to the free memory to a first value includes:

[0065] Set the allocated memory amount of the allocation function of the non-movable space to a first value.

[0066] The allocation function for non-movable space can be considered as a function that realizes the allocation of non-movable space. In this embodiment, the amount of allocated memory of the allocation function for non-movable space can be set through hook technology.

[0067] In one embodiment, setting the amount of released memory corresponding to the free memory to a second value includes:

[0068] Setting the amount of released memory of the release function for non-movable space to a second value.

[0069] The release function for non-movable space can be considered as a function that realizes the release of non-movable space. In this embodiment, the amount of released memory of the release function for non-movable space can be set through hook technology.

[0070] In one embodiment, the first value and the second value are zero.

[0071] The first value and the second value are equal and both are zero, so as to not count the allocated free memory into the total allocated memory, thus avoiding memory leaks.

[0072] The memory allocation method of the present disclosure can be considered as a technical solution for increasing the heap memory limit of the Android Runtime (ART) virtual machine by using non-movable space (i.e., NonMovingSpace) to allocate memory. The ART virtual machine is the virtual machine used by the Android operating system to run application programs and is used to interpret and execute the bytecode of Android application programs.

[0073] In large Android App projects, problems such as insufficient memory often occur due to Java memory leaks or non-standard Java code writing. For such problems, it is often very difficult to fundamentally solve the problem at the source. Therefore, it is necessary to extend the heap memory limit from the Android ART virtual machine, reduce the OOM problem caused by insufficient memory, and improve the user experience.

[0074] The present disclosure provides an optimization solution for extending the heap memory limit, thereby alleviating the problem of application crashes caused by insufficient memory in large Android Apps. The technical solution starts from the implementation level of the ART virtual machine. When memory is insufficient, the free NonMovingSpace algorithm is used to allocate memory, realizing the expansion of the heap memory, reducing the probability of application crashes caused by insufficient memory for users, and improving the user experience.

[0075] The present disclosure realizes the extension of the heap memory limit in the following manner:

[0076] 1. Hook the thread-local allocation buffer expansion function, i.e., AllocWithNewTLAB, using the Inline hook method;

[0077] 2. In the hook function, determine whether the available heap memory is less than a set threshold (i.e., determine whether the available heap memory is less than the set threshold through the thread-local allocation buffer expansion function);

[0078] 3. When it is less than the threshold, call the memory allocation function of the virtual machine through the address, i.e., the AllocObjectWithAllocator function, and set the allocator type parameter, i.e., allocator_type, to the non-moving object type, i.e., the kAllocatorTypeNonMoving type, to trigger the Non moving space to allocate memory and achieve heap memory expansion;

[0079] 4. Additionally, the upper limit of the heap memory is 512M. For the memory allocated by NonMovingSpace, it cannot be counted into the total memory allocated by the Heap, otherwise it will directly result in an OOM. Therefore, the allocation function of the non-moving space, i.e., DlmallocSpace, i.e., the Alloc() allocation and release function, i.e., Free(), can be Hooked, and the allocated memory amount and released memory amount returned by DlmallocSpace can be set to 0. The allocated memory amount and released memory amount returned can be returned to AllocObjectWithAllocato.

[0080] Heap memory is a memory management mechanism in a computer operating system, used for dynamically allocating and releasing memory space. Heap memory is usually used to store variables, data structures, and objects dynamically allocated during program runtime.

[0081] When a program needs to allocate memory, it can obtain a specified-sized memory space from the heap by calling the heap memory allocation function. The program can read and write to this memory and release it back to the heap by calling the heap memory release function (such as free) when it is no longer needed. Heap usually refers to the heap memory (Heap Memory) of the virtual machine. Heap memory is the memory area used by the virtual machine for dynamically allocating objects.

[0082] Figure 3 It is a schematic structural diagram of a memory allocation device provided by an embodiment of the present disclosure, as Figure 3 shown, the device includes:

[0083] A determination module 310, configured to determine the status information of the available heap memory through the thread-local allocation buffer expansion function;

[0084] An allocation module 320, configured to allocate free memory corresponding to a virtual machine when the status information is in a state of waiting for memory expansion;

[0085] A first setting module 330, configured to set the allocated memory amount corresponding to the free memory to a first value;

[0086] A second setting module 340, configured to set the released memory amount corresponding to the free memory to a second value.

[0087] The technical solution provided by the embodiments of the present disclosure reduces the problem of application crashes caused by insufficient memory. By judging the status information of the available heap memory, it is determined whether to allocate free memory corresponding to the virtual machine to achieve memory expansion, avoiding the problem of application crashes caused by insufficient memory.

[0088] In one embodiment, the determination module 310 is specifically configured to:

[0089] Judge whether the available heap memory is less than a set threshold through a thread-local allocation buffer expansion function;

[0090] If so, set the status information of the available heap memory to a state of waiting for memory expansion.

[0091] In one embodiment, the allocation module 320 is specifically configured to:

[0092] Set the allocator type of the memory allocation function to a non-movable object type, and the non-movable object type is the type corresponding to the free memory.

[0093] In one embodiment, the allocation module 320 is specifically configured to:

[0094] Call the memory allocation function of the virtual machine, and set the allocator type of the memory allocation function to a non-movable object type.

[0095] In one embodiment, the first setting module 330 is specifically configured to:

[0096] Set the allocated memory amount of the allocation function of the non-movable space to a first value.

[0097] In one embodiment, the second setting module 340 is specifically configured to:

[0098] Set the released memory amount of the release function of the non-movable space to a second value.

[0099] In one embodiment, the first value and the second value are zero.

[0100] The memory allocation device provided by an embodiment of the present disclosure can execute the memory allocation method provided by any embodiment of the present disclosure, and has functional modules and beneficial effects corresponding to the execution of the method.

[0101] It should be noted that the various units and modules included in the above device are only divided according to functional logic, but are not limited to the above 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 mutual distinction and do not limit the protection scope of the embodiments of the present disclosure.

[0102] Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. The following refers to Figure 4 which shows a schematic structural diagram of an electronic device (such as Figure 4 the terminal device or server in

[0103] The electronic device 500 includes:

[0104] One or more processing devices 501;

[0105] A storage device 508 for storing one or more programs,

[0106] When the one or more programs are executed by the one or more processing devices 501, the one or more processing devices 501 implement the memory allocation method provided by the embodiment of the present disclosure.

[0107] The terminal device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The illustrated electronic device 500 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.

[0108] As Figure 4 shown, the electronic device 500 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage device 508 into the random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. The editing / output (I / O) interface 505 is also connected to the bus 504.

[0109] Generally, the following devices can be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 can allow the electronic device 500 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 4 the electronic device 500 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices can be implemented or had.

[0110] 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 codes for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication device 509, or installed from the storage device 508, or installed from the ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0111] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only for illustrative purposes, and are not used to limit the scope of these messages or information.

[0112] 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. Technical details not described in detail in this embodiment can be seen in the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.

[0113] The embodiment of the present disclosure provides a computer storage medium, on which a computer program is stored, and when the program is executed by a processor, the memory allocation method provided by the above embodiment is implemented.

[0114] It should be noted that the above computer-readable medium of the present disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination of the two.

[0115] The computer storage medium can be a storage medium for computer-executable instructions, and the computer-executable instructions are used to execute the method provided by the present disclosure when executed by a computer processor.

[0116] A computer-readable storage medium may, for example, but is not limited to, a system, apparatus, or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of the computer-readable storage medium 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, the computer-readable storage medium may be any tangible medium that contains or stores a program, which can be used by or in conjunction with an instruction execution system, apparatus, or device. And in the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, which can 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 by any appropriate medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0117] In some embodiments, the client and the server may communicate using any currently known or future-developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of the communication network include a local area network (“LAN”), a wide area network (“WAN”), the Internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future-developed network.

[0118] The above computer-readable medium may be included in the above electronic device; or may exist separately without being assembled into the electronic device.

[0119] The above computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device is caused to:

[0120] The above computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device is caused to: determine the status information of the available heap memory through a thread-local allocation buffer expansion function;

[0121] When the status information is in the state of waiting for expansion, allocate idle memory corresponding to the virtual machine;

[0122] Set the allocated memory amount corresponding to the idle memory to a first value;

[0123] Set the released memory amount corresponding to the idle memory to a second value.

[0124] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or combinations thereof. The above-mentioned programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).

[0125] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.

[0126] The modules or units involved in the embodiments of the present disclosure may be implemented in software or in hardware. Among them, the name of the module or unit does not constitute a limitation to the unit itself in some cases. For example, the determination module may also be described as the "status information determination module".

[0127] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that can be used include: Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), Systems on a Chip (SOCs), Complex Programmable Logic Devices (CPLDs), and so on.

[0128] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media would include electrical connections based on one or more wires, portable computer disks, hard disks, Random Access Memory (RAM), Read Only Memory (ROM), Erasable Programmable Read Only Memory (EPROM or flash memory), optical fibers, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0129] According to one or more embodiments of the present disclosure, [Example 1] provides a memory allocation method, including:

[0130] Determining status information of available heap memory through a thread-local allocation buffer expansion function;

[0131] Allocating free memory corresponding to the virtual machine in the case where the status information is in a state to be expanded;

[0132] Setting the allocated memory amount corresponding to the free memory to a first value;

[0133] Setting the released memory amount corresponding to the free memory to a second value.

[0134] According to one or more embodiments of the present disclosure, [Example 2] provides the method described in Example 1, where determining the status information of available heap memory through a thread-local allocation buffer expansion function includes:

[0135] Judging whether the available heap memory is less than a set threshold through a thread-local allocation buffer expansion function;

[0136] If so, setting the status information of the available heap memory to a state to be expanded.

[0137] According to one or more embodiments of the present disclosure, [Example 3] provides the method described in Example 1, and the allocating the free memory corresponding to the virtual machine includes:

[0138] Set the allocator type of the memory allocation function to a non-movable object type, where the non-movable object type is the type corresponding to the free memory.

[0139] According to one or more embodiments of the present disclosure, [Example 4] provides the method described in Example 3, and the setting the allocator type of the memory allocation function to a non-movable object type includes:

[0140] Call the memory allocation function of the virtual machine and set the allocator type of the memory allocation function to a non-movable object type.

[0141] According to one or more embodiments of the present disclosure, [Example 5] provides the method described in Example 1, and the setting the allocated memory amount corresponding to the free memory to a first value includes:

[0142] Set the allocated memory amount of the allocation function of the non-movable space to a first value.

[0143] According to one or more embodiments of the present disclosure, [Example 6] provides the method described in Example 1, and the setting the released memory amount corresponding to the free memory to a second value includes:

[0144] Set the released memory amount of the release function of the non-movable space to a second value.

[0145] According to one or more embodiments of the present disclosure, [Example 7] provides the method described in Example 1, and the first value and the second value are zero.

[0146] According to one or more embodiments of the present disclosure, [Example 8] provides a memory allocation device, including:

[0147] A determination module, configured to determine the status information of the available heap memory through a thread-local allocation buffer expansion function;

[0148] An allocation module, configured to allocate the free memory corresponding to the virtual machine when the status information is in a state to be expanded;

[0149] A first setting module, configured to set the allocated memory amount corresponding to the free memory to a first value;

[0150] A second setting module, configured to set the released memory amount corresponding to the free memory to a second value.

[0151] According to one or more embodiments of the present disclosure, [Example 9] provides an electronic device, and the electronic device includes:

[0152] One or more processing devices;

[0153] A storage device for storing one or more programs,

[0154] When the one or more programs are executed by the one or more processing devices, the one or more processing devices implement the memory allocation method as described in any one of Examples 1-7.

[0155] According to one or more embodiments of the present disclosure, [Example 10] provides a storage medium containing computer-executable instructions that, when executed by a computer processor, are used to execute the memory allocation method as described in any one of Examples 1-7.

[0156] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles applied. 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 the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosure concept. For example, the technical solutions formed by mutually replacing the above features with the (but not limited to) technical features having similar functions disclosed in the present disclosure.

[0157] In addition, although the operations are depicted in a particular order, this should not be construed as requiring that the operations be performed in the particular order shown or in sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although a number of specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments may also be implemented combinatorially in a single embodiment. Conversely, the various features described in the context of a single embodiment may also be implemented separately or in any suitable sub-combination in multiple embodiments.

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

Claims

1. A memory allocation method, characterized in that, including: determining status information of available heap memory through a thread-local allocation buffer expansion function; allocating free memory corresponding to the virtual machine when the status information is in a state to be expanded; setting the allocated memory amount corresponding to the free memory to a first value; setting the released memory amount corresponding to the free memory to a second value.

2. The method according to claim 1, wherein The determining status information of available heap memory through a thread-local allocation buffer expansion function includes: judging whether the available heap memory is less than a set threshold through a thread-local allocation buffer expansion function; if so, setting the status information of the available heap memory to a state to be expanded.

3. The method according to claim 1, wherein The allocating free memory corresponding to the virtual machine includes: setting the allocator type of the memory allocation function to a non-movable object type, where the non-movable object type is the type corresponding to the free memory.

4. The method according to claim 3, characterized in that, The setting the allocator type of the memory allocation function to a non-movable object type includes: invoking the memory allocation function of the virtual machine and setting the allocator type of the memory allocation function to a non-movable object type.

5. The method according to claim 1, wherein The setting the allocated memory amount corresponding to the free memory to a first value includes: setting the allocated memory amount of the allocation function for the non-movable space to a first value.

6. The method according to claim 1, wherein The setting the released memory amount corresponding to the free memory to a second value includes: setting the released memory amount of the release function for the non-movable space to a second value.

7. The method according to claim 1, characterized in that The first value and the second value are zero.

8. A memory allocation device, characterized in that, including: a determining module for determining status information of available heap memory through a thread-local allocation buffer expansion function; an allocation module for allocating free memory corresponding to the virtual machine when the status information is in a state to be expanded; a first setting module for setting the allocated memory amount corresponding to the free memory to a first value; a second setting module for setting the released memory amount corresponding to the free memory to a second value.

9. An electronic device, characterized in that, The electronic device includes: one or more processing devices; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processing devices, enabling the one or more processing devices to implement the memory allocation method according to any one of claims 1-7.

10. A storage medium containing computer-executable instructions, where the computer-executable instructions are used to execute the memory allocation method according to any one of claims 1-7 when executed by a computer processor.