CN112685333B - Heap memory management method and device - Google Patents

Heap memory management method and device Download PDF

Info

Publication number
CN112685333B
CN112685333B CN202011575014.8A CN202011575014A CN112685333B CN 112685333 B CN112685333 B CN 112685333B CN 202011575014 A CN202011575014 A CN 202011575014A CN 112685333 B CN112685333 B CN 112685333B
Authority
CN
China
Prior art keywords
memory block
memory
node
target
allocated
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011575014.8A
Other languages
Chinese (zh)
Other versions
CN112685333A (en
Inventor
郭建慧
李灿灿
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Chuanggong Telecom Technology Co Ltd
Original Assignee
Shanghai Chuanggong Telecom Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Chuanggong Telecom Technology Co Ltd filed Critical Shanghai Chuanggong Telecom Technology Co Ltd
Priority to CN202011575014.8A priority Critical patent/CN112685333B/en
Publication of CN112685333A publication Critical patent/CN112685333A/en
Application granted granted Critical
Publication of CN112685333B publication Critical patent/CN112685333B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Memory System (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a heap memory management method and device, wherein the method comprises the following steps: acquiring an idle memory block linked list; any node of the free memory block linked list stores the size of a memory block corresponding to the node; each node in the idle memory block chain table is arranged according to a preset rule; searching the sizes of the memory blocks corresponding to the nodes according to a preset sequence, and determining a first target memory block in the heap memory; the preset sequence is determined according to the preset rule; the first target memory block is: the minimum memory block in the heap memory is not smaller than the memory space to be allocated; and if the first difference value between the space of the first target memory block and the memory space to be allocated is not greater than a first threshold value, taking the first target memory block as the allocated memory block.

Description

Heap memory management method and device
Technical Field
The present invention relates to the field of heap memory management technologies, and in particular, to a heap memory management method and apparatus.
Background
Heap memory allows programs to dynamically apply for memory space of a certain size during runtime, which facilitates the design and operation of the program, and many computer processing systems involve heap memory. The heap memory is managed as a problem if the allocation and release of memory blocks is required frequently. Since the program must use memory with continuous addresses each time it runs, heap memory is allocated with a block of memory with continuous addresses each time.
For a larger section of memory, directly allocating it out causes a large amount of memory waste. In order to ensure full utilization of the heap memory, a plurality of small-segment memories are segmented and distributed for a plurality of times. However, as the number of times of using the heap memory increases, a plurality of continuous but smaller memories may appear in the whole heap memory, and these memory spaces become fragmented memories due to the smaller memories, so that it is difficult to allocate an operating program as memory blocks, and these fragments are accumulated in a small amount, so that a part of the space of the heap memory is wasted, which is the problem of fragmentation of the heap memory. Currently, fragmentation of heap memory is common and needs to be solved.
Disclosure of Invention
The invention provides a heap memory management method and device, which solve the problem of fragmentation of a heap memory in the prior art.
In a first aspect, the present invention provides a heap memory management method, including: acquiring an idle memory block linked list; any node of the free memory block linked list stores the size of a memory block corresponding to the node; each node in the idle memory block chain table is arranged according to a preset rule;
Searching the sizes of the memory blocks corresponding to the nodes according to a preset sequence, and determining a first target memory block in the heap memory; the preset sequence is determined according to the preset rule; the first target memory block is: the minimum memory block in the heap memory is not smaller than the memory space to be allocated;
And if the first difference value between the space of the first target memory block and the memory space to be allocated is not greater than a first threshold value, taking the first target memory block as the allocated memory block.
Under the method, any node of the free memory block linked list stores the size of the memory block corresponding to the node and is arranged according to a preset rule, so that the size of the memory block corresponding to each node can be found through a preset sequence, and a first target memory block in the heap memory is determined, so that the first target memory block is the memory block with the memory space closest to the memory space to be allocated, and the space of the first target memory block is enough to be allocated, and if the first difference value between the space of the first target memory block and the memory space to be allocated is not greater than a first threshold value, the additional allocation space of the first target memory block is smaller than the set first threshold value, and the additional memory after the segmentation is not required to be fragmented memory, thereby alleviating the fragmentation phenomenon of the heap memory.
Optionally, if the first difference value is not smaller than a second threshold value, the first target memory block is segmented into a first sub-target memory block and a second sub-target memory block; the second threshold is greater than the first threshold; the difference value between the space of the first sub-target memory block and the memory space to be allocated is not greater than the first threshold value;
and taking the first sub-target memory block as an allocated memory block.
In the above method, since the second threshold is greater than the first threshold, if the first difference is not less than the second threshold, it indicates that the memory of the heap memory except the first target memory block is greater than the set second threshold, and the heap memory can still be used as a subsequent memory, so that the memory is not fragmented after being cut.
Optionally, if the first difference is greater than the first threshold and less than the second threshold, searching the size of the memory block corresponding to each node according to the preset sequence, and determining a second target memory block in the heap memory; the second target memory block is: a minimum memory block in the heap memory, wherein a second difference value between the heap memory and the memory space to be allocated is not smaller than the second threshold value;
and taking the second target memory block as the first target memory block, and returning to the step of dividing the first target memory block into a first sub-target memory block and a second sub-target memory block.
In the above method, if the first difference value is greater than the first threshold value and less than the second threshold value, it is explained that the space after the segmentation is not fragmented, but is difficult to be used as a subsequent use, so that the size of the memory block corresponding to each node can be searched according to the preset sequence until the second target memory block is found and used as the first target memory block, and therefore the first target memory block is not fragmented after the segmentation.
Optionally, the space of the first sub-target memory block is equal to the memory space to be allocated.
In the above manner, the heap memory space can be maximally utilized, so that the remaining second sub-target memory blocks are maximized.
Optionally, the preset rule specifically includes: and arranging the order of the nodes according to the size of the memory block corresponding to the nodes.
Optionally, when the order of the nodes is arranged from large to small according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that searching from the tail node to the head node of the idle memory block linked list in sequence;
when the order of the nodes is arranged from small to large according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that the nodes are searched from the head node to the tail node of the idle memory block linked list in sequence.
In the above manner, no matter the order of the nodes is arranged from large to small or from small to large according to the corresponding memory block sizes, the first target memory block with the first difference value not greater than the first threshold value is searched from the memory block size corresponding to the idle memory block linked list from small to large and is used as the allocated memory block.
Optionally, acquiring a memory block total linked list; the memory block total linked list sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks;
And aiming at any node of the memory block total linked list, when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, merging the memory block of the node, the memory block of the previous node and/or the memory block of the next node, thereby updating the memory block total linked list.
In the above manner, the total linked list of memory blocks sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks, so that when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, the memory blocks are merged, so that the memory block of the merged node is larger.
In a second aspect, the present invention provides a heap memory management apparatus, including: the acquisition module is used for acquiring the idle memory block linked list; any node of the free memory block linked list stores the size of a memory block corresponding to the node; each node in the idle memory block chain table is arranged according to a preset rule;
the searching module is used for searching the sizes of the memory blocks corresponding to the nodes according to a preset sequence and determining a first target memory block in the heap memory; the preset sequence is determined according to the preset rule; the first target memory block is: the minimum memory block in the heap memory is not smaller than the memory space to be allocated;
And the processing module is used for taking the first target memory block as the allocated memory block if the first difference value between the space of the first target memory block and the memory space to be allocated is not larger than a first threshold value.
Optionally, the processing module is further configured to:
if the first difference value is not smaller than a second threshold value, the first target memory block is segmented into a first sub-target memory block and a second sub-target memory block; the second threshold is greater than the first threshold; the difference value between the space of the first sub-target memory block and the memory space to be allocated is not greater than the first threshold value;
and taking the first sub-target memory block as an allocated memory block.
Optionally, the processing module is further configured to:
If the first difference value is larger than the first threshold value and smaller than the second threshold value, searching the size of the memory block corresponding to each node according to the preset sequence, and determining a second target memory block in the heap memory; the second target memory block is: a minimum memory block in the heap memory, wherein a second difference value between the heap memory and the memory space to be allocated is not smaller than the second threshold value;
and taking the second target memory block as the first target memory block, and returning to the step of dividing the first target memory block into a first sub-target memory block and a second sub-target memory block.
Optionally, the space of the first sub-target memory block is equal to the memory space to be allocated.
Optionally, the preset rule specifically includes: and arranging the order of the nodes according to the size of the memory block corresponding to the nodes.
Optionally, when the order of the nodes is arranged from large to small according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that searching from the tail node to the head node of the idle memory block linked list in sequence;
when the order of the nodes is arranged from small to large according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that the nodes are searched from the head node to the tail node of the idle memory block linked list in sequence.
Optionally, the acquiring module is further configured to: acquiring a total linked list of the memory blocks; the memory block total linked list sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks; the processing module is further configured to: and aiming at any node of the memory block total linked list, when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, merging the memory block of the node, the memory block of the previous node and/or the memory block of the next node, thereby updating the memory block total linked list.
The advantages of the foregoing second aspect and the advantages of the foregoing optional apparatuses of the second aspect may refer to the advantages of the foregoing first aspect and the advantages of the foregoing optional methods of the first aspect, and will not be described herein.
In a third aspect, the present invention provides a computer device comprising a program or instructions which, when executed, is operable to perform the above-described first aspect and the respective alternative methods of the first aspect.
In a fourth aspect, the present invention provides a storage medium comprising a program or instructions which, when executed, is adapted to carry out the above-described first aspect and the respective alternative methods of the first aspect.
These and other aspects of the invention will be more readily apparent from the following description of the embodiments.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the description of the embodiments will be briefly described below, it will be apparent that the drawings in the following description are only some embodiments of the present invention, and that other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart corresponding to a heap memory management method according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a memory allocation flow corresponding to a heap memory management method according to an embodiment of the present invention;
Fig. 3 is a schematic diagram of a memory release flow corresponding to a heap memory management method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a heap memory management device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail below with reference to the accompanying drawings, and it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
As shown in fig. 1, an embodiment of the present invention provides a heap memory management method.
Step 101: and acquiring a free memory block linked list.
Any node of the free memory block linked list stores the size of a memory block corresponding to the node; and each node in the idle memory block chain table is arranged according to a preset rule.
Step 102: and searching the sizes of the memory blocks corresponding to the nodes according to a preset sequence, and determining a first target memory block in the heap memory.
The preset sequence is determined according to the preset rule; the first target memory block is: and the minimum memory block in the heap memory is not smaller than the memory space to be allocated.
Step 103: and if the first difference value between the space of the first target memory block and the memory space to be allocated is not greater than a first threshold value, taking the first target memory block as the allocated memory block.
It should be noted that, the preset rule may be set according to a specific scenario, for example, the order of arranging the nodes according to the sizes of the memory blocks corresponding to the nodes, the order of arranging the nodes according to the identifiers of the memory blocks corresponding to the nodes, or the random arrangement of the nodes.
It should be noted that, no matter how the nodes are arranged, the result of the first target memory block is not changed, and how the preset rule and the preset sequence only affect the efficiency of searching the first target memory block, the minimum memory block in the heap memory is not smaller than the memory space to be allocated.
In an alternative embodiment, the preset rule specifically includes: and arranging the order of the nodes according to the size of the memory block corresponding to the nodes.
For example, the memory space to be allocated is 120KB, the first threshold is 20KB, and the free memory block linked list includes: an idle node 1, corresponding to the memory block size of 70KB; an idle node 2, corresponding to the memory block size 128KB; an idle node 3, corresponding to the memory block size 220KB; an idle node 4, corresponding to the memory block size of 500KB; the arrangement sequence of each node in the idle memory block chain table is as follows: idle node 1; an idle node 2; an idle node 3; an idle node 4; the arrangement sequence of each node in the idle memory block chain table can be as follows: an idle node 4; an idle node 3; an idle node 2; idle node 1.
Obviously, the first target memory block is a memory block corresponding to the idle node 2, the size of the memory block is 128KB, and the first difference value is 8KB and is not greater than the first threshold value of 20KB, so that the memory block corresponding to the idle node 2 is allocated to the memory space to be allocated.
In an optional implementation manner, when the order of the nodes is arranged from large to small according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that searching from the tail node to the head node of the idle memory block linked list in sequence; when the order of the nodes is arranged from small to large according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that the nodes are searched from the head node to the tail node of the idle memory block linked list in sequence.
For example, the arrangement order of the nodes in the idle memory block linked list is as follows: idle node 1; an idle node 2; an idle node 3; an idle node 4; the preset sequence is specifically that searching is sequentially carried out from a first node to a tail node, namely an idle node 1; an idle node 2; an idle node 3; and (4) idle nodes.
In another possible scenario, the arrangement order of the nodes in the idle memory block linked list may also be: an idle node 4; an idle node 3; an idle node 2; idle node 1; the preset sequence is specifically that searching from the tail node to the head node in turn, namely an idle node 1; an idle node 2; an idle node 3; the node 4 is idle, so that the first target memory block can be found as soon as possible.
In the above manner, no matter the order of the nodes is arranged from large to small or from small to large according to the corresponding memory block sizes, the first target memory block with the first difference value not greater than the first threshold value is searched from small to large according to the memory block sizes corresponding to the idle memory block linked list and is used as the allocated memory block.
In the manner of step 101 to step 103, if the first difference between the space of the first target memory block and the memory space to be allocated is not greater than the first threshold, the first target memory block is the memory block with the memory space closest to the memory space to be allocated, and the space of the first target memory block is sufficiently allocated, if the first difference between the space of the first target memory block and the memory space to be allocated is not greater than the first threshold, the space is not wasted, and the fragmentation of the heap memory is not necessary to be cut, thereby alleviating the fragmentation phenomenon of the heap memory.
In an alternative embodiment, if the first difference value is not smaller than a second threshold value, the first target memory block is segmented into a first sub-target memory block and a second sub-target memory block; the second threshold is greater than the first threshold; the difference value between the space of the first sub-target memory block and the memory space to be allocated is not greater than the first threshold value;
and taking the first sub-target memory block as an allocated memory block.
If the space to be allocated is 130KB, the first target memory block is a memory block corresponding to the idle node 3, and if the memory block size is 220KB, the first difference is 90KB, and the second threshold is 80KB, the first target memory block can be divided into a first sub-target memory block and a second sub-target memory block.
The difference value between the space of the first sub-target memory block and the memory space to be allocated is not larger than the first threshold value, so that the memory space to be allocated is allocated and is not wasted, and the difference value is not larger than the first threshold value.
Specifically, the size of the segmented second sub-target memory block can be set to be not smaller than the second threshold value, so that the segmented second sub-target memory block can be further distributed as a larger memory block.
In the above method, since the second threshold is greater than the first threshold, if the first difference is not less than the second threshold, it indicates that the memory of the heap memory except the first target memory block is greater than the set second threshold, and the heap memory can still be used as a subsequent memory, so that the memory is not fragmented after being cut.
It should be noted that, the space of the first sub-target memory block may be equal to the memory space to be allocated.
In the above manner, the heap memory space can be maximally utilized, so that the remaining second sub-target memory blocks are maximized.
Further, in an alternative embodiment, if the first difference is greater than the first threshold and less than the second threshold, the size of the memory block corresponding to each node is searched according to the preset sequence, and a second target memory block in the heap memory is determined; the second target memory block is: and the second difference value between the heap memory and the memory space to be allocated is not smaller than the minimum memory block of the second threshold value.
For example, if the space to be allocated is 150KB, the first target memory block is a memory block corresponding to the idle node 3, and the memory block size is 220KB, and the first difference is 70KB, greater than the first threshold value of 20KB, but smaller than the second threshold value of 80KB, and the direct allocation results in that the space waste is not within the first threshold value of the acceptable range, but after the splitting, the remaining memory blocks are not within the acceptable range, so the search can be continued until the second target memory block is found.
And taking the second target memory block as the first target memory block, and returning to the step of dividing the first target memory block into a first sub-target memory block and a second sub-target memory block.
In the above method, if the first difference value is greater than the first threshold value and less than the second threshold value, it is explained that the space after the segmentation is not fragmented, but is difficult to be used as a subsequent use, so that the size of the memory block corresponding to each node can be searched according to the preset sequence until the second target memory block is found and used as the first target memory block, and therefore the first target memory block is not fragmented after the segmentation.
Optionally, acquiring a memory block total linked list; the memory block total linked list sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks;
And aiming at any node of the memory block total linked list, when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, merging the memory block of the node, the memory block of the previous node and/or the memory block of the next node, thereby updating the memory block total linked list.
In the above manner, the total linked list of memory blocks sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks, so that when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, the memory blocks are merged, so that the memory block of the merged node is larger.
Next, a memory allocation flow corresponding to a heap memory management method according to an embodiment of the present invention is described in detail with reference to fig. 2.
Each memory block in the heap memory comprises a data head for management, the data head comprises a preset flag bit, and whether the memory block is allocated or not can be determined by indicating the preset flag bit of each memory block.
The unallocated memory blocks in the heap memory are maintained through an idle memory block linked list, and the idle memory blocks in the heap memory maintenance memory block are arranged from small to large according to the size sequence.
When memory blocks are allocated, the memory blocks can be searched from the head of the idle memory block linked list in turn until the memory block (the first target memory block) with a proper size is searched, and the size of the searched memory block is not smaller than the size to be applied.
If the size of the searched memory block is equal to the application size (not greater than a first threshold), directly distributing the searched memory block to application; if the size of the found memory block is larger (not smaller than the second threshold value), the found memory block is split into an A memory block and a B memory block (the size of the A memory block is the same as the application size).
The A memory block is used by the applicant, the B memory block is hung on the idle linked list, and the idle linked list of the memory block is ordered again after being distributed. Because the memory blocks on the idle memory linked list are orderly arranged from small to large, the large-size memory blocks are avoided from being searched during allocation as much as possible, so that the splitting of the memory blocks during allocation is reduced, the memory fragmentation is reduced, and the follow-up memory application can apply for a proper memory.
Next, a memory release flow corresponding to a heap memory management method according to an embodiment of the present invention is described in detail with reference to fig. 3.
When the memory block is released, the preset mark position of the memory block to be released is firstly unused.
And judging whether the front and rear memory blocks are unused, if not, fusing the memory block to be released and the front memory block or the rear memory block into a memory, and orderly inserting the memory block into an idle memory block linked list according to the size of the memory block, so as to ensure that the idle linked list of the inserted memory block is orderly arranged.
If the memory block to be released can not be fused with the previous memory block or the next memory block, the memory block to be released is directly and orderly inserted into the idle memory block linked list, and the release is finished.
The heap memory application and release method arranges the idle linked lists of the system memory blocks in order, reduces fragmentation in the use process of the memory blocks while ensuring that the memory blocks are applied and released in order, ensures that the application can apply to the memory blocks with proper size, and greatly improves the stability of the system.
As shown in fig. 4, the present invention provides a heap memory management apparatus, including: an obtaining module 401, configured to obtain an idle memory block linked list; any node of the free memory block linked list stores the size of a memory block corresponding to the node; each node in the idle memory block chain table is arranged according to a preset rule;
the searching module 402 is configured to search the sizes of the memory blocks corresponding to the nodes according to a preset sequence, and determine a first target memory block in the heap memory; the preset sequence is determined according to the preset rule; the first target memory block is: the minimum memory block in the heap memory is not smaller than the memory space to be allocated;
and a processing module 403, configured to take the first target memory block as an allocated memory block if the first difference between the space of the first target memory block and the memory space to be allocated is not greater than a first threshold.
Optionally, the processing module 403 is further configured to:
if the first difference value is not smaller than a second threshold value, the first target memory block is segmented into a first sub-target memory block and a second sub-target memory block; the second threshold is greater than the first threshold; the difference value between the space of the first sub-target memory block and the memory space to be allocated is not greater than the first threshold value;
and taking the first sub-target memory block as an allocated memory block.
Optionally, the processing module 403 is further configured to:
If the first difference value is larger than the first threshold value and smaller than the second threshold value, searching the size of the memory block corresponding to each node according to the preset sequence, and determining a second target memory block in the heap memory; the second target memory block is: a minimum memory block in the heap memory, wherein a second difference value between the heap memory and the memory space to be allocated is not smaller than the second threshold value;
and taking the second target memory block as the first target memory block, and returning to the step of dividing the first target memory block into a first sub-target memory block and a second sub-target memory block.
Optionally, the space of the first sub-target memory block is equal to the memory space to be allocated.
Optionally, the preset rule specifically includes: and arranging the order of the nodes according to the size of the memory block corresponding to the nodes.
Optionally, when the order of the nodes is arranged from large to small according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that searching from the tail node to the head node of the idle memory block linked list in sequence;
when the order of the nodes is arranged from small to large according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that the nodes are searched from the head node to the tail node of the idle memory block linked list in sequence.
Optionally, the obtaining module 401 is further configured to: acquiring a total linked list of the memory blocks; the memory block total linked list sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks; the processing module 403 is further configured to: and aiming at any node of the memory block total linked list, when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, merging the memory block of the node, the memory block of the previous node and/or the memory block of the next node, thereby updating the memory block total linked list.
Based on the same inventive concept, the embodiments of the present invention also provide a computer device, including a program or an instruction, when the program or the instruction is executed, the heap memory management method and any optional method provided in the embodiments of the present invention are executed.
Based on the same inventive concept, the embodiments of the present invention also provide a computer readable storage medium including a program or an instruction, when the program or the instruction is executed, the heap memory management method and any optional method provided in the embodiments of the present invention are executed.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present invention without departing from the spirit or scope of the invention. Thus, it is intended that the present invention also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (8)

1. A heap memory management method, comprising:
acquiring an idle memory block linked list; any node of the free memory block linked list stores the size of a memory block corresponding to the node; each node in the idle memory block chain table is arranged according to a preset rule;
Searching the sizes of the memory blocks corresponding to the nodes according to a preset sequence, and determining a first target memory block in the heap memory; the preset sequence is determined according to the preset rule; the first target memory block is: the minimum memory block in the heap memory is not smaller than the memory space to be allocated;
If the first difference value between the space of the first target memory block and the memory space to be allocated is not greater than a first threshold value, the first target memory block is used as an allocated memory block;
if the first difference value is not smaller than a second threshold value, the first target memory block is segmented into a first sub-target memory block and a second sub-target memory block; the second threshold is greater than the first threshold; the difference value between the space of the first sub-target memory block and the memory space to be allocated is not greater than the first threshold value;
taking the first sub-target memory block as an allocated memory block;
If the first difference value is larger than the first threshold value and smaller than the second threshold value, searching the size of the memory block corresponding to each node according to the preset sequence, and determining a second target memory block in the heap memory; the second target memory block is: a minimum memory block in the heap memory, wherein a second difference value between the heap memory and the memory space to be allocated is not smaller than the second threshold value;
and taking the second target memory block as the first target memory block, and returning to the step of dividing the first target memory block into a first sub-target memory block and a second sub-target memory block.
2. The method of claim 1, wherein the space of the first sub-target memory block is equal to the memory space to be allocated.
3. The method of claim 1, wherein the preset rule is specifically: and arranging the order of the nodes according to the size of the memory block corresponding to the nodes.
4. The method of claim 3, wherein when the order of the nodes is arranged from large to small according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that searching from the tail node to the head node of the idle memory block linked list in turn;
when the order of the nodes is arranged from small to large according to the sizes of the memory blocks corresponding to the nodes, the preset order is specifically that the nodes are searched from the head node to the tail node of the idle memory block linked list in sequence.
5. The method of any one of claims 1 to 4, further comprising:
Acquiring a total linked list of the memory blocks; the memory block total linked list sequentially stores the sizes of the memory blocks according to the address sequence of the memory blocks;
And aiming at any node of the memory block total linked list, when the memory block corresponding to the node is released, if the memory block of the previous node of the node and/or the memory block of the next node of the node are not used, merging the memory block of the node, the memory block of the previous node and/or the memory block of the next node, thereby updating the memory block total linked list.
6. A heap memory management apparatus, comprising:
The acquisition module is used for acquiring the idle memory block linked list; any node of the free memory block linked list stores the size of a memory block corresponding to the node; each node in the idle memory block chain table is arranged according to a preset rule;
the searching module is used for searching the sizes of the memory blocks corresponding to the nodes according to a preset sequence and determining a first target memory block in the heap memory; the preset sequence is determined according to the preset rule; the first target memory block is: the minimum memory block in the heap memory is not smaller than the memory space to be allocated;
the processing module is used for taking the first target memory block as an allocated memory block if the first difference value between the space of the first target memory block and the memory space to be allocated is not larger than a first threshold value;
if the first difference value is not smaller than a second threshold value, the first target memory block is segmented into a first sub-target memory block and a second sub-target memory block; the second threshold is greater than the first threshold; the difference value between the space of the first sub-target memory block and the memory space to be allocated is not greater than the first threshold value;
taking the first sub-target memory block as an allocated memory block;
If the first difference value is larger than the first threshold value and smaller than the second threshold value, searching the size of the memory block corresponding to each node according to the preset sequence, and determining a second target memory block in the heap memory; the second target memory block is: a minimum memory block in the heap memory, wherein a second difference value between the heap memory and the memory space to be allocated is not smaller than the second threshold value;
and taking the second target memory block as the first target memory block, and returning to the step of dividing the first target memory block into a first sub-target memory block and a second sub-target memory block.
7. A computer device comprising a program or instructions which, when executed, performs the method of any of claims 1 to 5.
8. A computer readable storage medium comprising a program or instructions which, when executed, performs the method of any one of claims 1 to 5.
CN202011575014.8A 2020-12-28 2020-12-28 Heap memory management method and device Active CN112685333B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011575014.8A CN112685333B (en) 2020-12-28 2020-12-28 Heap memory management method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011575014.8A CN112685333B (en) 2020-12-28 2020-12-28 Heap memory management method and device

Publications (2)

Publication Number Publication Date
CN112685333A CN112685333A (en) 2021-04-20
CN112685333B true CN112685333B (en) 2024-06-07

Family

ID=75452206

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011575014.8A Active CN112685333B (en) 2020-12-28 2020-12-28 Heap memory management method and device

Country Status (1)

Country Link
CN (1) CN112685333B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113296703B (en) * 2021-05-27 2022-08-05 山东云海国创云计算装备产业创新中心有限公司 Heap memory management method, device, equipment and medium
CN113268349B (en) * 2021-06-04 2022-02-18 科东(广州)软件科技有限公司 Computer memory management method, device, equipment and storage medium
CN113485835B (en) * 2021-07-14 2022-04-22 深圳大趋智能科技有限公司 Method, system, equipment and medium for realizing memory sharing under multiple scenes

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6105053A (en) * 1995-06-23 2000-08-15 Emc Corporation Operating system for a non-uniform memory access multiprocessor system
CN1963788A (en) * 2005-11-08 2007-05-16 中兴通讯股份有限公司 A managing method for EMS memory
WO2018018896A1 (en) * 2016-07-29 2018-02-01 华为技术有限公司 Memory management apparatus and method
CN108038002A (en) * 2017-12-15 2018-05-15 天津津航计算技术研究所 A kind of embedded software EMS memory management process
CN109375985A (en) * 2018-09-06 2019-02-22 新华三技术有限公司成都分公司 Dynamic memory management method and device
CN110209490A (en) * 2018-04-27 2019-09-06 腾讯科技(深圳)有限公司 A kind of EMS memory management process and relevant device
CN111078410A (en) * 2019-12-11 2020-04-28 Oppo(重庆)智能科技有限公司 Memory allocation method and device, storage medium and electronic equipment
CN111104347A (en) * 2019-12-23 2020-05-05 北京东土军悦科技有限公司 Heap memory block searching method, device, equipment and storage medium
CN111338981A (en) * 2020-02-21 2020-06-26 深圳震有科技股份有限公司 Memory fragmentation prevention method and system and storage medium
CN111352861A (en) * 2020-02-19 2020-06-30 Oppo广东移动通信有限公司 Memory compression method and device and electronic equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9239757B2 (en) * 2014-05-30 2016-01-19 Sandisk Technologies Inc. Method and apparatus for relocating data in non-volatile memory
KR20180059208A (en) * 2016-11-25 2018-06-04 삼성전자주식회사 Memory controller with reclaim controller

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6105053A (en) * 1995-06-23 2000-08-15 Emc Corporation Operating system for a non-uniform memory access multiprocessor system
CN1963788A (en) * 2005-11-08 2007-05-16 中兴通讯股份有限公司 A managing method for EMS memory
WO2018018896A1 (en) * 2016-07-29 2018-02-01 华为技术有限公司 Memory management apparatus and method
CN108038002A (en) * 2017-12-15 2018-05-15 天津津航计算技术研究所 A kind of embedded software EMS memory management process
CN110209490A (en) * 2018-04-27 2019-09-06 腾讯科技(深圳)有限公司 A kind of EMS memory management process and relevant device
CN109375985A (en) * 2018-09-06 2019-02-22 新华三技术有限公司成都分公司 Dynamic memory management method and device
CN111078410A (en) * 2019-12-11 2020-04-28 Oppo(重庆)智能科技有限公司 Memory allocation method and device, storage medium and electronic equipment
CN111104347A (en) * 2019-12-23 2020-05-05 北京东土军悦科技有限公司 Heap memory block searching method, device, equipment and storage medium
CN111352861A (en) * 2020-02-19 2020-06-30 Oppo广东移动通信有限公司 Memory compression method and device and electronic equipment
CN111338981A (en) * 2020-02-21 2020-06-26 深圳震有科技股份有限公司 Memory fragmentation prevention method and system and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
宋敏超 ; 李少波 ; .一种新型嵌入式动态内存分配算法.计算机应用.2017,249-252+259. *

Also Published As

Publication number Publication date
CN112685333A (en) 2021-04-20

Similar Documents

Publication Publication Date Title
CN112685333B (en) Heap memory management method and device
CN108132842B (en) Embedded software memory management system
CN108038002B (en) Embedded software memory management method
US20020144073A1 (en) Method for memory heap and buddy system management for service aware networks
KR101994021B1 (en) File manipulation method and apparatus
US11042477B2 (en) Memory management using segregated free lists
CN107066498B (en) Key value KV storage method and device
CN106557427B (en) Memory management method and device for shared memory database
CN105843819B (en) Data export method and device
CN110674052B (en) Memory management method, server and readable storage medium
CN105718319B (en) Memory pool layout analysis method and memory pool device
CN103186469A (en) Memory allocation method and device, and memory recovery method
CN114546295B (en) Intelligent writing distribution method and device based on ZNS solid state disk
CN108932271B (en) File management method and device
CN108829523A (en) Memory source distribution method, device, electronic equipment and readable storage medium storing program for executing
CN112579595A (en) Data processing method and device, electronic equipment and readable storage medium
CN114327917A (en) Memory management method, computing device and readable storage medium
CN104850505A (en) Memory management method and system based on chain type stacking
CN103106147A (en) Memory allocation method and system
CN105528371A (en) Method, device, and system for executing writing task
CN114296658B (en) Storage space allocation method and device, terminal equipment and storage medium
CN105469173A (en) Method of optimal management on static memory
CN111177021A (en) Java card fragment management method and storage device thereof
CN111338981B (en) Memory fragmentation prevention method and system and storage medium
CN109660471B (en) Pointer recovery method and device based on FPGA

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant