Memory management method and device

By detecting free memory blocks in the memory pool and combining them with dynamic system memory allocation, the data loss problem caused by insufficient memory pool pre-allocation is solved, memory utilization efficiency is improved, and fragmented memory is reduced.

CN120803694APending Publication Date: 2025-10-17ALIBABA (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510804228.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-16
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Existing memory allocation methods have the problem of insufficient memory pool pre-allocation leading to data loss, and low memory utilization efficiency, which easily leads to fragmented memory.

Method used

By receiving memory allocation requests, detecting free memory blocks in the memory pool, using the memory management linked list to determine the memory blocks to be allocated, and dividing dynamic memory blocks in the system memory, it provides memory services by combining fixed allocation of the memory pool with dynamic allocation of system memory.

Benefits of technology

This avoids data loss caused by insufficient pre-allocation of the memory pool, improves memory utilization efficiency, and reduces memory fragmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803694A_ABST
    Figure CN120803694A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a memory management method and device. According to the embodiment of the invention, the method comprises the steps: receiving a memory allocation request, and determining at least one to-be-allocated memory block in free memory blocks according to a memory demand length corresponding to the memory allocation request and a memory management linked list when detecting that the free memory blocks are included in a memory pool, and when detecting that the total memory length of each to-be-allocated memory block does not meet the memory demand length, dividing the system memory according to the total memory length of each to-be-allocated memory block and the memory demand length to obtain a dynamic memory block, and allocating each to-be-allocated memory block and the dynamic memory block to a target memory block allocation object. Therefore, the memory allocation service is provided by combining the fixed allocation of the memory pool and the dynamic allocation of the system memory, the problem of data loss caused by insufficient pre-allocated memory of the memory pool can be avoided, meanwhile, the utilization efficiency of the memory is improved, and the fragmented memory is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of memory management, and more particularly, to a memory management method and device. BACKGROUND

[0002] Memory is an essential resource in the process of program running. Reasonably allocating memory for programs can effectively improve the running efficiency of programs. However, the existing memory allocation method usually adopts a fixed allocation manner of a memory pool to provide memory allocation services, which has certain limitations. For example, when the pre-allocated memory of the memory pool is insufficient, the existing memory management method will have a data loss problem. At the same time, the memory utilization efficiency of the existing memory allocation method is usually low, and it is easy to produce fragmented memory. SUMMARY

[0003] Therefore, the embodiments of the present application provide a memory management method and device to avoid the data loss problem caused by insufficient pre-allocated memory of the memory pool, improve the memory utilization efficiency, and reduce fragmented memory.

[0004] In a first aspect, the embodiments of the present application aim to provide a memory management method, which comprises:

[0005] receiving a memory allocation request;

[0006] in response to detecting that the memory pool includes a free memory block, determining at least one to-be-allocated memory block in the free memory block according to a memory demand length corresponding to the memory allocation request and a memory management linked list, wherein the memory management linked list is used to record a continuous free memory area in the memory pool, and the free memory block is an unallocated memory block;

[0007] in response to detecting that the total memory length of each to-be-allocated memory block does not meet the memory demand length, dividing a dynamic memory block in the system memory according to the total memory length of each to-be-allocated memory block and the memory demand length;

[0008] allocating each to-be-allocated memory block and the dynamic memory block to a target memory block allocation object.

[0009] In a second aspect, the embodiments of the present application aim to provide a memory management device, which comprises:

[0010] a receiving unit configured to receive a memory allocation request;

[0011] The memory block to be allocated determining unit is configured to, in response to detecting that the memory pool includes a free memory block, determine at least one memory block to be allocated in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management linked list, wherein the memory management linked list is configured to record a continuous free memory region in the memory pool, and the free memory block is an unallocated memory block;

[0012] The dynamic memory block dividing unit is configured to, in response to detecting that the total memory length of each of the memory blocks to be allocated does not satisfy the memory requirement length, divide a dynamic memory block in the system memory according to the total memory length of each of the memory blocks to be allocated and the memory requirement length.

[0013] The allocating unit is configured to allocate each of the memory blocks to be allocated and the dynamic memory block to a target memory block allocation object.

[0014] In a third aspect, an embodiment of the present application aims to provide a computer readable storage medium, which stores computer program instructions, and the computer program instructions, when executed by a processor, implement the method in the first aspect.

[0015] In a fourth aspect, an embodiment of the present application aims to provide an electronic device, which comprises:

[0016] A memory configured to store one or more computer program instructions;

[0017] A processor configured to execute the one or more computer program instructions to implement the method in the first aspect.

[0018] In a fifth aspect, an embodiment of the present application aims to provide a computer program product, which, when running on a computer, causes the computer to execute the method in the first aspect.

[0019] The embodiment of the present application can receive a memory allocation request, and in response to detecting that the memory pool includes a free memory block, determine at least one memory block to be allocated in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management linked list, and in response to detecting that the total memory length of each of the memory blocks to be allocated does not satisfy the memory requirement length, divide a dynamic memory block in the system memory according to the total memory length of each of the memory blocks to be allocated and the memory requirement length, and then allocate each of the memory blocks to be allocated and the dynamic memory block to a target memory block allocation object. The memory management linked list is configured to record a continuous free memory region in the memory pool. Thus, the embodiment of the present application can provide a memory allocation service by combining a fixed allocation of a memory pool and a dynamic allocation of a system memory, can avoid data loss caused by insufficient pre-allocated memory of the memory pool, can improve memory utilization efficiency, and can reduce fragmented memory. BRIEF DESCRIPTION OF DRAWINGS

[0020] The foregoing and other objects, features and advantages of the present application will become more apparent from the following description of an embodiment thereof taken in conjunction with the accompanying drawings in which:

[0021] Figure 1 Flowchart of the memory management system of the embodiment of the present application;

[0022] Figure 2 Flowchart of the memory management method of the embodiment of the present application;

[0023] Figure 3 Schematic diagram of the memory management chain table and the memory pool of the embodiment of the present application;

[0024] Figure 4 Flowchart of the memory pool creation method of the embodiment of the present application;

[0025] Figure 5 Schematic diagram of the memory management chain table and the memory pool of the embodiment of the present application;

[0026] Figure 6 Schematic diagram of the identification bit of the embodiment of the present application;

[0027] Figure 7 Schematic diagram of the identification bit of the embodiment of the present application;

[0028] Figure 8 Flowchart of the memory block release method of the embodiment of the present application;

[0029] Figure 9 Schematic diagram of the memory management chain table and the memory pool of the embodiment of the present application;

[0030] Figure 10 Schematic diagram of the memory management bitmap of the embodiment of the present application;

[0031] Figure 11 Schematic diagram of the memory management chain table and the memory pool of the embodiment of the present application;

[0032] Figure 12 Schematic diagram of the memory management device of the embodiment of the present application;

[0033] Figure 13 Schematic diagram of the electronic device of the embodiment of the present application. DETAILED DESCRIPTION

[0034] The present application is described below based on examples, but the present application is not limited to only these examples. In the following detailed description of the present application, some specific details are described in detail. The present application can also be fully understood without the description of these details by those skilled in the art. In order to avoid confusion of the essence of the present application, well-known methods, processes, procedures, elements and circuits are not described in detail.

[0035] In addition, those of ordinary skill in the art will appreciate that the drawings provided herein are for illustrative purposes and are not necessarily drawn to scale.

[0036] Unless the context clearly requires otherwise, throughout the description, the words "comprise", "comprising", and the like are to be construed in an inclusive sense as opposed to an exclusive or exhaustive sense; that is to say, in the sense of "including, but not limited to".

[0037] In the description of the present application, it is to be understood that the terms "first", "second" and the like are used only for descriptive purposes and are not to be construed as indicating or implying relative importance. In addition, in the description of the present application, unless otherwise stated, the meaning of "a plurality of" is two or more.

[0038] The solutions described in the specification and examples, if involving personal information processing, will be processed on the premise of having legal basis (such as obtaining the consent of the subject of personal information, or being necessary for the performance of a contract, etc.), and will only be processed within the prescribed or agreed range. Users who refuse to process personal information other than the necessary information required for basic functions will not affect the user's use of basic functions.

[0039] Figure 1 The flowchart of the memory management system of the embodiments of the present application is shown in FIG. 1. As shown in FIG. 1, the memory management system includes a system memory 11, a memory usage object 12, and a memory management device 13. Figure 1

[0040] ​The system memory 11 can be a provider of memory space. In the embodiment of the present application, the system memory 11 can be used to provide memory space externally. Alternatively, the system memory 11 can be implemented by any type of storage medium or a combination of multiple types of storage medium, such as a random access memory, a solid state disk, a hard disk drive, a read-only memory register, or a combination of the above storage medium, etc., which is not limited in the present application. Alternatively, the memory space provided by the system memory 11 can include physical memory and / or virtual memory, which is not limited in the present application. The memory usage object 12 can be a corresponding application, which can be a usage object of memory space. In the embodiment of the present application, when the memory usage object 12 is invoked, in order to ensure that the memory usage object 12 can run normally, the memory usage object 12 can instruct the memory management device 13 to create a memory pool including multiple memory blocks in the system memory 11 for use by the memory usage object 12. Further, the memory usage object 12 can include multiple memory block allocation objects 121. It should be understood that the memory block allocation object 121 can specifically refer to a thread, an instance, or a module, etc. code unit inside an application. The memory block allocation object 121 can be an allocation object of each memory block in the memory pool. Each memory block in the memory pool can be allocated by the memory management device 13 to different memory block allocation objects 121 for use by the memory block allocation objects 121. The memory management device 13 can communicate and interact data with the system memory 11 and the memory usage object 12. The memory management device 13 can be used in cooperation with the system memory 11 to provide memory-related services to the memory usage object 12, such as memory pool creation service, memory block allocation service based on the memory pool, dynamic memory block allocation service, and memory block release, etc. Alternatively, the memory management device 13 can be implemented by software, hardware, or a combination of software and hardware, which is not limited in the present application.

[0041] Specifically, in Figure 1In the illustrated memory management system, when the memory usage object 12 is invoked, the memory usage object 12 can send a memory space usage request to the memory management device 13. Upon receiving the memory space usage request, the memory management device 13 can create a memory pool including a plurality of memory blocks for the memory usage object 12 to use in the system memory 11 according to the memory space usage request. Further, when the memory usage object 12 is running, for each memory block allocation object 121 of the memory usage object 12, the memory block allocation object 121 can send a memory allocation request to the memory management device 13. Upon receiving the memory allocation request, the memory management device 13 can detect whether the memory pool includes a free memory block. If so, the memory management device 13 can determine at least one to-be-allocated memory block in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management linked list. And, upon determining the to-be-allocated memory block in the memory pool, the memory management device 13 can detect whether a total memory length of each to-be-allocated memory block satisfies the memory requirement length. If not, the memory management device 13 can divide a dynamic memory block in the system memory according to the total memory length of each to-be-allocated memory block and the memory requirement length. Further, the memory management device 13 can allocate each to-be-allocated memory block and the dynamic memory block to the memory block allocation object 121. The memory management linked list is used to record a continuous free memory region in the memory pool, and the free memory block is an unallocated memory block.

[0042] Thus, by combining the fixed allocation of the memory pool and the dynamic allocation of the system memory to provide the memory allocation service, the embodiment of the present application can avoid the problem of data loss caused by insufficient pre-allocated memory of the memory pool, and improve the memory utilization efficiency and reduce fragmented memory.

[0043] It is intended to be explained that, although Figure 1 Only a certain number of memory usage objects 12 are shown in the memory management system, but this does not mean that the number is limited. In actual application, the memory management system can also include a plurality of memory usage objects. Further, when the memory management system includes a plurality of memory usage objects, the memory management device can be used to provide memory-related services to different memory usage objects respectively. Alternatively, the memory management system can also correspondingly include a plurality of memory management devices, and each memory management device can be used to provide memory-related services to the corresponding memory usage object.

[0044] Optionally, the scheme in the embodiments of the present application can be applicable to a local running scenario or a cloud running scenario, and the present application does not limit this. Furthermore, when the scheme in the embodiments of the present application is applicable to a local running scenario, the system memory 11 can be a system memory of a local device. The memory usage object 12 can be a local application program running by the local device. It should be understood that at this time, the memory management apparatus can be connected with the system memory 11 and the memory usage object 12 through a bus to realize communication with each other. When the scheme in the embodiments of the present application is applicable to a cloud running scenario, the system memory 11 can be a system memory located in a cloud platform. The memory usage object 12 can be a client program deployed and running in a corresponding device. It should be understood that at this time, the memory management apparatus can be connected with the memory usage object 12 through a bus, and connected with the system memory 11 through a wireless network to realize communication with each other.

[0045] Figure 2 The flowchart of the memory management method of the embodiments of the present application. It should be understood that the execution subject of the memory management method can be the memory management apparatus in the above embodiments. As shown in the figure, the memory management method can specifically include the following steps: Figure 2

[0046] Step S100, receiving a memory allocation request.

[0047] Specifically, the memory management apparatus can receive a memory allocation request triggered by a target memory block allocation object. The target memory block allocation object can be any one of the memory block allocation objects in the memory usage object that has a memory allocation demand. It should be understood that the memory allocation request can be triggered by the target memory block allocation object by calling a corresponding Application Programming Interface Function (API) function.

[0048] Step S200, in response to detecting that the memory pool includes a free memory block, determining at least one to-be-allocated memory block in the free memory block according to a memory demand length corresponding to the memory allocation request and a memory management linked list.

[0049] Specifically, after receiving the memory allocation request, the memory management apparatus can detect whether the memory pool includes a free memory block. If yes, the memory management apparatus can determine at least one to-be-allocated memory block in the free memory block according to a memory demand length corresponding to the memory allocation request and a memory management linked list. The memory demand length can be a memory length requested to be allocated by the target memory block allocation object. The memory management linked list is used to record a continuous free memory area in the memory pool. The free memory block is an unallocated memory block.

[0050] ​Optionally, as an implementation of a memory management linked list, the memory management linked list can be configured to include multiple linked list nodes. Each linked list node can be configured to represent a different continuous free memory area in the memory pool. It should be understood that a continuous free memory area can include a single free memory block or multiple free memory blocks with continuous addresses. More specifically, each linked list node can represent the corresponding continuous free memory area by recording the number of free memory blocks in the corresponding continuous free memory area and the starting address of the first free memory block.

[0051] Figure 3 Schematic diagram of the memory management linked list and memory pool of an embodiment of the present invention. It should be understood that Figure 3 The rectangular area covered by the shadow can be used to represent the unallocated memory block (that is, the free memory block), and the rectangular area not covered by the shadow can be used to represent the allocated memory block. Figure 3 As shown, the memory management linked list may include linked list nodes A, B, C, and D. Each linked list node may be used to represent a different continuous free memory area in the memory pool. For example, linked list node A may be used to represent a continuous free memory area 31 in the memory pool, linked list node B may be used to represent a continuous free memory area 32 in the memory pool, linked list node C may be used to represent a continuous free memory area 33 in the memory pool, and linked list node D may be used to represent a continuous free memory area 34 in the memory pool. It should be understood that a continuous free memory area may include a single free memory block (as shown by continuous free memory areas 31 and 34) or multiple free memory blocks with continuous addresses (as shown by continuous free memory areas 32 and 33). Furthermore, each linked list node can represent the corresponding continuous free memory area by recording the number of free memory blocks and the starting address of the first free memory block in the corresponding continuous free memory area. For example, linked list node A can represent continuous free memory area 31 by recording that the number of free memory blocks is 1 and the starting address of the first free memory block is 0x1. Linked list node B can represent continuous free memory area 32 by recording that the number of free memory blocks is 3 and the starting address of the first free memory block is 0x3. Linked list node C can represent continuous free memory area 33 by recording that the number of free memory blocks is 2 and the starting address of the first free memory block is 0x8. Linked list node D can represent continuous free memory area 34 by recording that the number of free memory blocks is 1 and the starting address of the first free memory block is 0x12. It should be understood that Figure 3 The memory management linked list and memory pool shown are only for illustration. In actual application, the memory management linked list and memory pool are not limited to Figure 3 The scale and content shown in.

[0052] Optionally, the memory management linked list can be a one-way linked list or a two-way linked list, and this application does not limit this. Also, as a way of arranging the linked list nodes in the memory management linked list, each linked list node can be arranged in the memory management linked list in the order of the addresses of the continuous free memory areas represented in the memory pool (such as Figure 3 Alternatively, each linked list node may be arranged in the memory management linked list in the order in which it is added to the memory management linked list, and this application does not impose any restrictions on this.

[0053] Optionally, in step S200, as an implementation method for determining the memory blocks to be allocated, the memory management device can select free memory blocks as memory blocks to be allocated in the continuous free memory areas represented by each linked list node from back to front or from front to back according to the arrangement order of each linked list node in the memory management linked list, until the total memory length of the memory blocks to be allocated is equal to the memory requirement length or all the free memory blocks in the memory pool are selected.

[0054] by Figure 3 Taking the memory management linked list and memory pool shown as an example, when determining the memory block to be allocated, the memory management device may first select a free memory block from the continuous free memory area represented by linked list node A as the memory block to be allocated, and then select a free memory block from the continuous free memory area represented by linked list node B as the memory block to be allocated, and select a free memory block from the continuous free memory area represented by linked list node C as the memory block to be allocated, and finally select a free memory block from the continuous free memory area represented by linked list node D as the memory block to be allocated. Alternatively, the memory management device may first select a free memory block from the continuous free memory area represented by linked list node D as the memory block to be allocated, and then select a free memory block from the continuous free memory area represented by linked list node C as the memory block to be allocated, and select a free memory block from the continuous free memory area represented by linked list node B as the memory block to be allocated, and finally select a free memory block from the continuous free memory area represented by linked list node A as the memory block to be allocated.

[0055] Figure 4 This is a flow chart of a memory pool creation method according to an embodiment of the present invention. It should be understood that Figure 4 The memory pool creation method shown can be executed by the memory management device before providing memory block allocation services for the memory block allocation object. By executing the memory pool creation method, the memory management device can create a memory pool including multiple memory blocks for the memory usage object to use, and generate a corresponding memory management linked list for the memory pool. Figure 4 As shown, the memory pool creation method may specifically include the following steps:

[0056] Step S110, receiving a memory space usage request.

[0057] Specifically, the memory management apparatus can receive a memory space usage request triggered by a memory usage object. It should be understood that the memory space usage request can be triggered by the memory usage object by calling a corresponding Application Programming Interface Function (API) function.

[0058] Step S120, determining a memory usage requirement of the memory usage object according to the memory space usage request.

[0059] Specifically, after receiving the memory space usage request, the memory management apparatus can determine a memory usage requirement of the memory usage object according to the memory space usage request.

[0060] Step S130, dividing a target memory region in the system memory according to the memory usage requirement.

[0061] Specifically, after determining the memory usage requirement of the memory usage object, the memory management apparatus can divide a target memory region in the system memory according to the memory usage requirement.

[0062] Optionally, the memory usage requirement can at least include a length requirement of the memory usage object for the used memory. In step S130, the memory management apparatus can perform memory region division in the system memory according to the length requirement, so as to divide the target memory region.

[0063] Step S140, dividing a plurality of memory blocks in the target memory region to create the memory pool.

[0064] Specifically, after obtaining the target memory region, the memory management apparatus can divide a plurality of memory blocks in the target memory region to create the memory pool.

[0065] Optionally, in an embodiment of the present application, the memory lengths of the memory blocks in the memory pool can be the same. Further optionally, the memory usage requirement can include a quantity division requirement or a memory length division requirement of the memory usage object for the memory blocks in the memory pool. In step S140, the memory management apparatus can divide a plurality of memory blocks in the target memory region according to the quantity division requirement or the memory length division requirement, so as to create the memory pool.

[0066] Step S150, generating a memory management linked list corresponding to the memory pool.

[0067] Specifically, after the memory pool is created, the memory management apparatus can generate a memory management linked list corresponding to the memory pool. It is to be explained that for a newly created memory pool, each memory block inside the newly created memory pool can be regarded as a complete continuous free memory region. Thus, the memory management linked list generated by the memory management apparatus for the newly created memory pool can only contain a single linked list node. However, with the provision of subsequent memory block allocation services and memory block release services, the number of linked list nodes in the memory management linked list can dynamically change, and the present application does not limit the number of linked list nodes in the memory management linked list.

[0068] Step S300, in response to detecting that the total memory length of each of the to-be-allocated memory blocks does not satisfy the memory requirement length, dividing the system memory according to the total memory length of each of the to-be-allocated memory blocks and the memory requirement length to obtain dynamic memory blocks.

[0069] Specifically, after determining the to-be-allocated memory blocks in the memory pool, the memory management apparatus can further detect whether the total memory length of each of the to-be-allocated memory blocks satisfies the memory requirement length. If not, the memory management apparatus can divide the system memory according to the total memory length of each of the to-be-allocated memory blocks and the memory requirement length to obtain dynamic memory blocks.

[0070] Optionally, in step S300, when the dynamic memory blocks are divided in the system memory, as an implementation manner, the memory management apparatus can first determine the difference length between the total memory length of each of the to-be-allocated memory blocks and the memory requirement length. The difference length can be understood as the memory length of the dynamic memory blocks that need to be additionally divided in the system memory to satisfy the memory requirement length. Further, after determining the difference length, the memory management apparatus can divide the system memory according to the difference length to obtain the dynamic memory blocks.

[0071] Step S400, allocating each of the to-be-allocated memory blocks and the dynamic memory blocks to a target memory block allocation object.

[0072] Specifically, after dividing the dynamic memory blocks in the system memory, the memory management apparatus can allocate each of the to-be-allocated memory blocks and the dynamic memory blocks to a target memory block allocation object.

[0073] Optionally, in an embodiment of the present invention, after allocating each memory block to be allocated and dynamic memory block to the target memory block allocation object, the memory management device may delete or update the linked list node corresponding to each memory block to be allocated in the memory management linked list. Specifically, for each linked list node, the memory management device may delete or update the linked list node based on the allocation of free memory blocks in the continuous free memory area represented by the linked list node. Among them, for the linked list node in which all the free memory blocks in the represented continuous free memory area are allocated, the memory management device may directly delete the linked list node. Schematically, Figure 3 Taking the linked list node A in the example, assuming that all free memory blocks in the linked list node A are allocated, the memory management device can directly delete the linked list node A. For the linked list node in which some free memory blocks in the continuous free memory area are allocated, the memory management device can update the linked list node. It should be understood that here, updating the linked list node specifically refers to updating the information recorded in the linked list node. Schematically, Figure 3 Taking the linked list node B in the example, assuming that the first two free memory blocks in the linked list node B are allocated, the memory management device can update the number of free memory blocks recorded in the linked list node B from 3 to 1, and update the starting address of the first free memory block recorded in the linked list node B from 0x3 to 0x5.

[0074] Figure 5 Schematic diagram of memory management linked list and memory pool in an embodiment of the present invention. Figure 3 In the memory management linked list and memory pool, after all free memory blocks in linked list node A and the first two free memory blocks in linked list node B are allocated to the target memory block allocation object, the memory management device can delete and update the linked list nodes in the memory management linked list to obtain Figure 5 The memory management linked list and memory pool shown in Figure 2. Figure 5 As shown, compared with Figure 3 The memory management linked list in Figure 5 The memory management linked list in the program deletes linked list node A and updates linked list node B to linked list node B'.

[0075] Optionally, to ensure that each memory block can be released to its original source location (i.e., the memory pool or system memory) when the memory block is subsequently reclaimed, the memory management device may further fill source identification information into corresponding identification bits for each memory block to be allocated and dynamic memory block before allocating the memory block to the target memory block allocation object. The source identification information is used to indicate the allocation source of the memory block.

[0076] Further optionally, as a setting method of the identification bit, the identification bit can be set in each memory block. Specifically, an identification bit can be set in each memory block, and the source identification information of each memory block can be filled in the identification bit of each memory block in the form of binary data. It should be understood that the specific position of the preset bit in each memory block and the specific content of the source identification information can be set by relevant personnel, and this application does not limit this. Illustratively, for example, the preset bit can be located at the first byte of the memory block, and the source identification information used to represent that the memory block comes from the memory pool can be "00000000", and the source identification information used to represent that the memory block comes from the system memory can be "10000000".

[0077] Figure 6 Schematic diagram of the identification bit of the embodiment of the present invention. Figure 6 As shown, the first byte of the memory block 61 can be set as an identification bit. The identification bit can be filled with source identification information such as "10000000" to indicate that the source of the memory block 61 is the system memory.

[0078] Alternatively, as another way to set the identification bit, the identification bit can also be set in the first memory block of a memory block with continuous addresses. Specifically, when the addresses of multiple memory blocks are continuous, in order to save space inside the memory blocks, the identification bits of the multiple memory blocks can be uniformly set in the first memory block. Compared to the above setting method, in this setting method, the source identification information can be used to represent the allocation source of the memory block in addition to representing the number of consecutive memory blocks. It should be understood that the specific location of the preset bit in the first memory block and the specific content of the source identification information can be set by relevant personnel, and this application does not limit this. Illustratively, for example, the preset bit can be located in the first two bytes of the first memory block, where the first byte of the first two bytes can be used to fill in the source identification information part that represents the source of the memory block, and the second byte can be used to fill in the source identification information part that represents the number of consecutive memory blocks. In the first byte, the source identification information part used to represent that the memory block comes from the memory pool can be "00000000", and the source identification information part used to represent that the memory block comes from the system memory can be "10000000". In the second byte, the number of consecutive memory blocks can be directly represented in binary form.

[0079] Figure 7 Schematic diagram of the identification bit of the embodiment of the present invention. It should be understood that Figure 7 Only the first memory block among multiple memory blocks with consecutive addresses is shown. Figure 7As shown, the first two bytes of the memory block 71 can be set as identification bits. Among them, the first byte of the first two bytes is filled with a source identification information part with a content of "00000000", to represent that the source of the plurality of memory blocks with continuous addresses is the memory pool. The second byte is filled with a source identification information part with a content of "00000101", to represent that the continuous number of memory blocks is 5.

[0080] It is intended to be explained that in the embodiments of the present application, different memory blocks can be set with identification bits in different ways. As an implementation manner, the dynamic memory block can be set with identification bits in the first identification bit setting manner. The address-continuous to-be-allocated memory block can be set with identification bits in the second identification bit setting manner. The separate to-be-allocated memory block can be set with identification bits in the first identification bit setting manner or the second identification bit setting manner. At the same time, in order to avoid the source identification information stored in the identification bits being changed in the process that the memory block allocation object uses the memory block, the preset bit in each memory block can be specifically set as unable to be deleted or changed by the memory allocation object.

[0081] Optionally, when the memory block allocation object uses the memory block, the memory management device can also provide a memory block release service.

[0082] Figure 8 The flowchart of the memory block release method of the embodiments of the present application is shown. It should be understood that by executing the memory block release method as shown in Figure 7 The memory management device can also provide a memory block release service for the memory block allocation object by executing the memory block release method as shown in Figure 8 The memory block release method can specifically include the following steps:

[0083] Step S410, receiving a memory release request.

[0084] Specifically, the memory management device can receive a memory release request triggered by a target memory block allocation object. Among them, the target memory block allocation object can be any one of the memory block allocation objects in the memory usage object that has a memory release demand. It should be understood that the memory release request can be triggered by the target memory block allocation object by calling a corresponding Application Programming Interface Function (API) function.

[0085] Step S420, determining at least one to-be-released memory block according to the memory release request.

[0086] Specifically, after receiving the memory release request, the memory management apparatus can determine at least one to-be-released memory block according to the memory release request. The to-be-released memory block can include a to-be-allocated memory block and a dynamic memory block previously allocated for the target memory block.

[0087] In step S430, the memory management apparatus can obtain the source identification information from the corresponding identification bit for each to-be-released memory block.

[0088] Specifically, after determining the to-be-released memory block, the memory management apparatus can obtain the source identification information from the corresponding identification bit for each to-be-released memory block.

[0089] Optionally, in step S430, according to the previously determined identification bit setting mode of each memory block, the memory management apparatus can determine the identification bit corresponding to each to-be-released memory block (i.e., the first byte of the to-be-released memory block or the first two bytes of the first to-be-released memory block in the plurality of to-be-released memory blocks with continuous addresses), and obtain the source identification information from the identification bit.

[0090] In step S440, the memory management apparatus can release each to-be-released memory block into the memory pool or the system memory according to the source identification information.

[0091] Specifically, after obtaining the source identification information, the memory management apparatus can release each to-be-released memory block into the memory pool or the system memory according to the source identification information.

[0092] Optionally, after releasing each to-be-released memory block into the memory pool or the system memory, the memory management apparatus can further add a corresponding link table node for each to-be-released memory block released into the memory pool in the memory management link table.

[0093] Optionally, in the process of adding the link table node, for a single to-be-released memory block, the memory management apparatus can add a link table node in the memory management link table to represent the to-be-released memory block through the link table node. As shown in FIG. 4B, assuming that the second memory block in the memory pool is a to-be-released memory block, the memory management apparatus can add a link table node E recording the number of free memory blocks as 1 and the starting address of the first free memory block as 0x2 in the memory management link table. Figure 5 Figure 5 As shown in FIG. 4C, assuming that the sixth and seventh memory blocks in the memory pool are to-be-released memory blocks, the memory management apparatus can add a link table node F recording the number of free memory blocks as 2 and the starting address of the first free memory block as 0x6 in the memory management link table.

[0094] ​It should be understood that when adding a chain table node to the memory management chain table, the chain table node can be added to the start position of the memory management chain table, can be added to the end position of the memory management chain table, or can be added to a corresponding position in the middle of the memory management chain table, which can depend on the arrangement rule of the memory management chain table itself, and the application does not limit this.

[0095] Figure 9 A schematic diagram of the memory management chain table and the memory pool of an embodiment of the application is shown in FIG. 1. It should be understood that for the memory management chain table and the memory pool in FIG. 1, when the first, the second, the third, the fourth, the fifth, the sixth, and the seventh memory blocks are released as to-be-released memory blocks, the memory management device can add chain table nodes to the memory management chain table to obtain the memory management chain table and the memory pool shown in FIG. 2. Figure 5 Figure 9 Figure 9 Figure 5 Figure 9

[0096] Optionally, after updating the chain table node in the memory management chain table each time, the memory management device can also merge a plurality of chain table nodes with continuous addresses in the memory management chain table according to the memory management bitmap. The memory management bitmap can be used to record the allocation states of the memory blocks in the memory pool in the order of addresses. Specifically, the memory management device can traverse the memory pool according to the memory management bitmap to find all continuous free areas in the current memory pool. Then, for each continuous free area, the memory management device can determine whether it has a plurality of corresponding chain table nodes in the memory management chain table, and if so, the memory management device can merge the plurality of corresponding chain table nodes.

[0097] Figure 10 A schematic diagram of the memory management bitmap of an embodiment of the application is shown in FIG. 10. It should be understood that the memory management bitmap shown in FIG. 10 can correspond to the memory pool in FIG. 1. Figure 10 Figure 9 Figure 10 As shown in FIG. 10, the memory management bitmap 101 can be used to record the allocation states of the memory blocks in the memory pool in the order of addresses. Each rectangular cell of the memory management bitmap 101 can be used to represent a corresponding memory block in the memory pool. The value “1” in the rectangular cell can be used to represent that the corresponding memory block is in the allocated state, and the value “0” in the rectangular cell can be used to represent that the corresponding memory block is in the unallocated state. It is to be explained that the memory management bitmap shown in FIG. 10 is only for the convenience of understanding, and the schematic diagram obtained after patterning the memory management bitmap does not mean that the memory management bitmap is limited to the schematic diagram in the actual application. Figure 10 Figure 10 ​​​​​​​​in the form shown in

[0098] Further, as Figure 9 and 10 shown, according to the memory management bitmap shown in Figure 10 , the memory management device can determine that the memory pool in Figure 9 includes three continuous free areas. Among them, for the second continuous free area, when it is judged that it has corresponding three list nodes B', C and F in the memory management list, the memory management device can merge the three list nodes B', C and F corresponding thereto.

[0099] Figure 11 is a schematic diagram of the memory management list and the memory pool of an embodiment of the present application. It should be understood that for the memory management list and the memory pool in Figure 9 , the memory management device can merge the three list nodes B', C and F in the memory management list to obtain the memory management list and the memory pool shown in Figure 11 . As shown in Figure 11 , compared with the memory management list in Figure 9 , the list nodes B', C and F are merged into the list node B".

[0100] Optionally, in an embodiment of the present application, if it is detected that the total memory length of each to-be-allocated memory block meets the memory requirement length, the memory management device can directly allocate each to-be-allocated memory block to the target memory block allocation object. In addition, if it is detected that the memory pool does not include a free memory block, the memory management device can directly divide the dynamic memory block according to the memory requirement length in the system memory, and allocate the dynamic memory block to the target memory block allocation object. Thus, by using the memory pool to provide memory allocation services when the memory pool includes sufficient free memory blocks, using the memory pool and the system memory to provide memory allocation services when the memory pool includes insufficient free memory blocks, and using the system memory to provide memory allocation services when the memory pool does not include a free memory block, an embodiment of the present application can provide memory allocation services in a manner of combining fixed allocation of the memory pool and dynamic allocation of the system memory, thereby avoiding the problem of data loss caused by insufficient pre-allocation of the memory pool, improving memory utilization efficiency, and reducing fragmented memory.

[0101] The embodiment of the present application receives a memory allocation request, and when detecting that the memory pool includes a free memory block, determines at least one to-be-allocated memory block in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management chain table, and when detecting that the total memory length of each to-be-allocated memory block does not satisfy the memory requirement length, divides a dynamic memory block in the system memory according to the total memory length of each to-be-allocated memory block and the memory requirement length, and then allocates each to-be-allocated memory block and the dynamic memory block to a target memory block allocation object. The memory management chain table is used to record a continuous free memory region in the memory pool. Thus, the embodiment of the present application can avoid the problem of data loss caused by insufficient pre-allocated memory of the memory pool, improve memory utilization efficiency, and reduce fragmented memory by combining fixed allocation of the memory pool with dynamic allocation of the system memory to provide a memory allocation service.

[0102] Figure 12 The figure is a schematic diagram of the memory management device of the embodiment of the present application. As shown in the figure, the memory management device of the embodiment of the present application includes a receiving unit 121, a to-be-allocated memory block determination unit 122, a dynamic memory block division unit 123, and an allocation unit 124. Figure 12

[0103] Specifically, the receiving unit 121 is configured to receive a memory allocation request.

[0104] The to-be-allocated memory block determination unit 122 is configured to, in response to detecting that the memory pool includes a free memory block, determine at least one to-be-allocated memory block in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management chain table, wherein the memory management chain table is used to record a continuous free memory region in the memory pool, and the free memory block is an unallocated memory block.

[0105] The dynamic memory block division unit 123 is configured to, in response to detecting that the total memory length of each to-be-allocated memory block does not satisfy the memory requirement length, divide a dynamic memory block in the system memory according to the total memory length of each to-be-allocated memory block and the memory requirement length.

[0106] The allocation unit 124 is configured to allocate each to-be-allocated memory block and the dynamic memory block to a target memory block allocation object.

[0107] ​The embodiment of the present application receives a memory allocation request, and when detecting that the memory pool includes a free memory block, determines at least one to-be-allocated memory block in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management linked list. When detecting that a total memory length of the to-be-allocated memory blocks does not meet the memory requirement length, divides a dynamic memory block in the system memory according to the total memory length of the to-be-allocated memory blocks and the memory requirement length, and then allocates the to-be-allocated memory blocks and the dynamic memory block to a target memory block allocation object. The memory management linked list is used to record a continuous free memory region in the memory pool. Thus, the embodiment of the present application can avoid the problem of data loss caused by insufficient pre-allocated memory of the memory pool, improve memory utilization efficiency, and reduce fragmented memory by providing a memory allocation service in a manner of combining fixed allocation of the memory pool and dynamic allocation of the system memory.

[0108] Figure 13 A schematic diagram of an electronic device according to an embodiment of the present application. It should be understood that the electronic device can specifically be a memory management apparatus for implementing the memory management method. As shown in the figure, the electronic device includes at least one processor 131, a memory 132 communicatively connected to the at least one processor 131, and a communication component 133 communicatively connected to a scanning apparatus, the communication component 133 receiving and sending data under the control of the processor 131; wherein the memory 132 stores instructions executable by the at least one processor 131, and the instructions are executed by the at least one processor 131 to implement the above-mentioned memory management method. Figure 13

[0109] Specifically, the electronic device includes one or more processors 131 and a memory 132, Figure 13 For example, the processor 131 is taken as an example. The processor 131 and the memory 132 can be connected through a bus or other means, Figure 13 For example, the bus connection is taken as an example. The memory 132 is a non-volatile computer readable storage medium, which can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The processor 131 executes various function applications and data processing of the device by running the non-volatile software programs, instructions and modules stored in the memory 132, that is, implements the above-mentioned memory management method.

[0110] ​The memory 132 can include a program storage area and a data storage area. The program storage area can store an operating system, at least one application required by a function, and the like. The data storage area can store an option list, and the like. In addition, the memory 132 can include a high-speed random access memory, and can further include a nonvolatile memory such as at least one of a magnetic disk storage device, a flash memory device, or other nonvolatile solid-state memory device. In some embodiments, the memory 132 can optionally include a memory disposed remotely with respect to the processor 131, and these remote memories can be connected to the external device through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0111] One or more modules are stored in the memory 132, and when executed by the one or more processors 131, perform the memory management method in any of the method embodiments described above.

[0112] The above products can perform the method provided by the embodiments of the present application, have the corresponding function modules and beneficial effects of performing the method, and the technical details not described in detail in the embodiments can be referred to the method provided by the embodiments of the present application.

[0113] The embodiments of the present application can receive a memory allocation request, and when detecting that the memory pool includes a free memory block, determine at least one to-be-allocated memory block in the free memory block according to a memory requirement length corresponding to the memory allocation request and a memory management linked list in the free memory block, and when detecting that a total memory length of the to-be-allocated memory blocks does not satisfy the memory requirement length, divide a dynamic memory block in the system memory according to the total memory length of the to-be-allocated memory blocks and the memory requirement length, and then allocate the to-be-allocated memory blocks and the dynamic memory block to a target memory block allocation object. The memory management linked list is used to record a continuous free memory region in the memory pool. In this way, the memory allocation service is provided by combining the fixed allocation of the memory pool and the dynamic allocation of the system memory, the embodiments of the present application can avoid the problem of data loss caused by insufficient pre-allocated memory of the memory pool, improve the memory utilization efficiency, and reduce the fragmentation of the memory.

[0114] Another embodiment of the present application relates to a non-volatile storage medium for storing a computer-readable program for causing a computer to execute part or all of the method embodiments described above.

[0115] That is, a person skilled in the art can understand that all or part of the steps in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a program stored in a storage medium, including a plurality of instructions for causing a device (which can be a single-chip microcomputer, a chip, etc.) or a processor to execute all or part of the steps of the methods described in the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0116] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A memory management method, characterized in that: The method comprises: Receive memory allocation request; In response to detecting that the memory pool includes free memory blocks, determining at least one memory block to be allocated in the free memory blocks according to a memory requirement length corresponding to the memory allocation request and a memory management linked list, wherein the memory management linked list is used to record continuous free memory areas in the memory pool, and the free memory blocks are unallocated memory blocks; In response to detecting that the total memory length of each of the memory blocks to be allocated does not meet the memory requirement length, dividing the system memory into dynamic memory blocks according to the total memory length of each of the memory blocks to be allocated and the memory requirement length; Allocate the memory blocks to be allocated and the dynamic memory blocks to a target memory block allocation object.

2. The method according to claim 1, characterized in that Before receiving the memory allocation request, the method further includes: Receive a memory space usage request; Determining a memory usage requirement of a memory usage object according to the memory space usage request; Dividing the system memory to obtain a target memory area according to the memory usage requirement; Divide a plurality of memory blocks within the target memory area to create the memory pool; Generate a memory management linked list corresponding to the memory pool.

3. The method according to claim 1, characterized in that The memory blocks in the memory pool have the same memory length.

4. The method according to claim 1, wherein The memory management linked list includes a plurality of linked list nodes, each of which is used to represent a different continuous free memory area in the memory pool. The continuous free memory area includes a single free memory block or a plurality of free memory blocks with continuous addresses.

5. The method according to claim 4, characterized in that After allocating the memory blocks to be allocated and the dynamic memory blocks to the target memory block allocation object, the method further includes: The linked list nodes corresponding to the memory blocks to be allocated are deleted or updated in the memory management linked list.

6. The method according to claim 4, characterized in that Before allocating each of the to-be-allocated memory blocks and the dynamic memory block to the target memory block allocation object, the method further includes: For each of the memory blocks to be allocated and the dynamic memory blocks, source identification information is filled into the corresponding identification bit, and the source identification information is used to represent the allocation source of the memory block.

7. The method according to claim 6, characterized in that After allocating the memory blocks to be allocated and the dynamic memory blocks to the target memory block allocation object, the method further includes: Receive memory release request; Determine at least one memory block to be released according to the memory release request, where the memory block to be released includes the memory block to be allocated and the dynamic memory block; For each of the memory blocks to be released, obtaining the source identification information at the corresponding identification bit; Each of the memory blocks to be released is released to the memory pool or the system memory according to the source identification information.

8. The method according to claim 7, characterized in that After releasing each of the to-be-released memory blocks to the memory pool or the memory pool, the method further includes: In the memory management linked list, a corresponding linked list node is added for each of the to-be-released memory blocks released into the memory pool.

9. The method according to claim 8, characterized in that After adding a corresponding linked list node for each of the to-be-released memory blocks released into the memory pool, the method further includes: A plurality of linked list nodes with consecutive addresses in the memory management linked list are merged according to a memory management bitmap, wherein the memory management bitmap is used to record the allocation status of each memory block in the memory pool in order of addresses.

10. The method according to any one of claims 6 or 7, characterized in that The identification bit is set in each of the memory blocks, or the identification bit is set in the first memory block of the memory blocks with consecutive addresses.

11. A memory management device, characterized in that: The device comprises: A receiving unit, configured to receive a memory allocation request; a memory block to be allocated determining unit, configured to, in response to detecting that a memory pool includes free memory blocks, determine at least one memory block to be allocated in the free memory blocks according to a memory requirement length corresponding to the memory allocation request and a memory management linked list, wherein the memory management linked list is used to record continuous free memory areas in the memory pool, and the free memory blocks are unallocated memory blocks; a dynamic memory block partitioning unit, configured to, in response to detecting that the total memory length of each of the memory blocks to be allocated does not meet the memory requirement length, partition the system memory according to the total memory length of each of the memory blocks to be allocated and the memory requirement length to obtain dynamic memory blocks; The allocation unit is used to allocate each of the memory blocks to be allocated and the dynamic memory block to a target memory block allocation object.

12. A computer-readable storage medium storing computer program instructions, characterized in that: The computer program instructions implement the method according to any one of claims 1 to 10 when executed by a processor.

13. An electronic device, characterized in that: The device comprises: a memory for storing one or more computer program instructions; A processor, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 10.

14. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to perform the method according to any one of claims 1 to 10.