[go: up one dir, main page]

CN112667152A - Heap memory management method and device, readable storage medium and electronic equipment - Google Patents

Heap memory management method and device, readable storage medium and electronic equipment Download PDF

Info

Publication number
CN112667152A
CN112667152A CN202011508383.5A CN202011508383A CN112667152A CN 112667152 A CN112667152 A CN 112667152A CN 202011508383 A CN202011508383 A CN 202011508383A CN 112667152 A CN112667152 A CN 112667152A
Authority
CN
China
Prior art keywords
continuous
bits
bit
heap memory
order
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.)
Granted
Application number
CN202011508383.5A
Other languages
Chinese (zh)
Other versions
CN112667152B (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.)
Chengdu Baiwei Storage Technology Co ltd
Original Assignee
Chengdu Baiwei Storage 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 Chengdu Baiwei Storage Technology Co ltd filed Critical Chengdu Baiwei Storage Technology Co ltd
Priority to CN202011508383.5A priority Critical patent/CN112667152B/en
Publication of CN112667152A publication Critical patent/CN112667152A/en
Application granted granted Critical
Publication of CN112667152B publication Critical patent/CN112667152B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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)

Abstract

The invention discloses a heap memory management method, a device, a readable storage medium and an electronic device, wherein the allocation address of the heap memory to be allocated is inquired by establishing a continuous bit position inquiry table and an index bitmap, and the bit position of the corresponding index bitmap is marked by a second identifier.

Description

Heap memory management method and device, readable storage medium and electronic equipment
Technical Field
The present invention relates to the field of data storage technologies, and in particular, to a heap memory management method and apparatus, a readable storage medium, and an electronic device.
Background
In an embedded system, management of heap memory is a necessary link for firmware implementation, various processing flows more or less require application and release of the heap memory, and a proper heap memory algorithm is usually selected to ensure timely effectiveness of heap memory allocation and release.
As is well known, TLSF (Two Level separated Fit)Segmented memory matching) algorithm is a heap memory allocation algorithm well suited for embedded domains; the algorithm uses an isolated matching mechanism to achieve a good matching strategy. The basic isolation matching mechanism uses a set of free lists, each array containing free blocks within a certain size range. To speed up access to free blocks and access to manage large numbers of isolation lists to reduce fragmentation, the list arrays have been organized into two level arrays. Referring to FIG. 1, the first level array classifies the size of the free memory blocks according to powers of 2, such as 16, 32, 64, and so on, and the second level array is linearly segmented on a first level basis, such as 26In this section, it is divided into four sub-regions, respectively [64,80 ], [80,96 ], [96,112) and [112, 128). Each array list has an associated bitmap for marking whether there is a memory block in the corresponding list, e.g., the last four bits of the bitmap of the first level are 0100, i.e., 26There is a free block in this interval, and the corresponding bitmap of the second level is 0010, then there is a free block in the [80,96) interval, and the free block is 89 Byte.
The TLSF algorithm indexes the memory blocks with proper size through two-stage bitmaps, and if the memory with proper size does not exist, the idle memory blocks need to be split necessarily; similarly, in the memory release operation, the adjacent idle memories need to be merged; it can be seen that the complexity of TLSF algorithm allocation and release in some typical scenarios tends to put some strain on firmware performance.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: the heap memory management method, the device, the readable storage medium and the electronic equipment are provided, so that the heap memory management is realized under the condition that the memory is not merged and split, and the management efficiency is improved.
In order to solve the technical problems, the invention adopts a technical scheme that:
a heap memory management method comprises the following steps:
establishing a continuous bit lookup table;
establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by a second identifier;
the first identifier is different from the second identifier.
In order to solve the technical problem, the invention adopts another technical scheme as follows:
a heap memory management apparatus, comprising:
the initialization module is used for establishing a continuous bit lookup table and establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
the allocation module is used for receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by using a second identification;
the first identifier is different from the second identifier.
In order to solve the technical problem, the invention adopts another technical scheme as follows:
a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the above-mentioned heap memory management method.
In order to solve the technical problem, the invention adopts another technical scheme as follows:
an electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the heap memory management method when executing the computer program.
The invention has the beneficial effects that: for the heap memory to be allocated, the allocation address of the heap memory to be allocated is inquired by establishing a continuous bit lookup table and an index bitmap, and the bit of the corresponding index bitmap is marked by using a second identifier.
Drawings
FIG. 1 is a diagram illustrating a TLSF free memory data structure in the prior art;
FIG. 2 is a flowchart illustrating steps of a heap memory management method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a heap memory management apparatus according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention;
Detailed Description
In order to explain technical contents, achieved objects, and effects of the present invention in detail, the following description is made with reference to the accompanying drawings in combination with the embodiments.
Referring to fig. 2, an embodiment of the present invention provides a heap memory management method, including:
establishing a continuous bit lookup table;
establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by a second identifier;
the first identifier is different from the second identifier.
From the above description, the beneficial effects of the present invention are: for the heap memory to be allocated, the allocation address of the heap memory to be allocated is inquired by establishing a continuous bit lookup table and an index bitmap, and the bit of the corresponding index bitmap is marked by using a second identifier.
Further, the establishing an index bitmap according to the size of the heap memory to be managed includes:
setting a preset memory size corresponding to one bit in the index bitmap;
calculating the byte number of the index bitmap according to the size of the heap memory to be managed and the size of the preset memory;
and establishing the index bitmap according to the byte number.
As can be seen from the above description, the index bitmap is set according to the size of the heap memory to be managed and the size of the preset byte, and the heap memory is managed by using the size of the preset memory as a unit, so that subsequent calculation of the heap memory address to be allocated is facilitated.
Further, the determining, according to the continuous bit lookup table, the index bitmap, and the size of the heap memory requested to be allocated, an address of the heap memory that matches the size of the heap memory requested to be allocated includes:
rounding the size of the heap memory requested to be allocated according to the preset memory size;
calculating the number of continuous bits required by the size of the heap memory requested to be allocated;
according to the continuous bit lookup table, judging whether the continuous bit quantity of the target continuous bit with the value of the first identification in the current byte selected by the index bitmap meets the required continuous bit quantity, if so, acquiring the target continuous bit, and if not, performing the judgment on the next byte of the index bitmap until the target continuous bit meeting the required continuous bit quantity is found;
and determining the address of the heap memory matched with the size of the heap memory according to the target continuous bit.
From the above description, it can be known that rounding the size of the heap memory requested to be allocated, calculating the required bit, and then querying each byte in the index bitmap can conveniently and quickly locate the target continuous bit meeting the requirement.
Further, the continuous bit lookup table includes a lower continuous bit number, an upper continuous bit number and a middle continuous maximum bit number;
the number of the low-order continuous bits is the number of the continuous bits of the first identifier from the low-order bits in the bit array with the preset length to be inquired;
the high-order continuous bit number is the continuous bit number of the first identifier from the high-order bit in the bit array with the preset length to be inquired;
the middle continuous maximum bit number is the maximum continuous bit number of the first identifier in a bit block with the second identifier at two ends and the first identifier in the middle in a bit array with preset length to be inquired;
the determining whether the number of consecutive bits having a value that satisfies the required number of consecutive bits of the target consecutive bits of the first identifier exists in the current byte selected by the index bitmap includes:
judging whether the number of the high-order continuous bits in the previous byte plus the number of the low-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits, when the current byte is the first byte of the index bitmap, the value of the number of the high-order continuous bits in the previous byte is zero, if so, determining that the number of the continuous bits having the target continuous bits with the value of the first identifier meets the required number of the continuous bits, and if not, judging whether the current byte is the first identifier;
if yes, adding eight to the number of the high-order continuous bits in the previous byte, entering the next byte, and returning to execute the operation of judging whether the number of the high-order continuous bits in the previous byte and the number of the low-order continuous bits in the current byte are more than or equal to the required number of the continuous bits, if not, judging whether the number of the middle continuous maximum bits in the current byte is more than or equal to the required number of the continuous bits;
if the number of the continuous bits of the target continuous bits with the value of the first identifier is greater than or equal to the required number of the continuous bits, determining whether the number of the high-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits;
if the number of the continuous bits is larger than or equal to the required number of the continuous bits, determining that the number of the continuous bits with the value of the target continuous bits of the first identifier meets the required number of the continuous bits, if the number of the continuous bits is smaller than the required number of the continuous bits, entering the next byte, and returning to execute the operation of judging whether the number of the high-order continuous bits in the previous byte and the number of the low-order continuous bits in the current byte are larger than or equal to the required number of the continuous bits until the target continuous bits meeting the required number of the continuous bits are found.
According to the description, the continuous bit quantity of the low-order continuous bit, the high-order continuous bit and the middle continuous bit of each byte is set in the continuous bit lookup table, so that the condition of the continuous bit in the byte is intuitively reflected, and convenience is provided for the query of the subsequent continuous bit; whether continuous bits meeting requirements exist in the low order, the middle order and the high order of each byte selected by the index bitmap or not is sequentially judged, and when the low order is compared, the low order continuous bits of the current byte and the high order continuous bits of one byte are compared, so that omission is avoided during searching, and optimal matching is realized.
Further, the obtaining the target continuous bits includes:
acquiring the high-order address bit position of the target continuous bit and the bit number of the target continuous bit;
the determining, according to the target continuous bits, an address of the heap memory that matches the size of the heap memory requested to be allocated includes:
determining the address of the heap memory matched with the size of the heap memory according to the high address bit position of the target continuous bit, the number of the target continuous bit and the preset memory size:
the address of the heap memory matched with the size of the heap memory requested to be allocated is the starting address of the heap memory + (the upper address bit position of the inquired continuous bits-the inquired continuous bit number) and the size of the preset memory.
From the above description, the bit position of the high address of the searched continuous bits and the number of the continuous bits are obtained, and the calculation is performed to obtain the allocated heap memory address accurately.
Further, the continuous bit lookup table further includes a lower address offset of the continuous bits corresponding to the middle continuous maximum bit number;
the obtaining the upper address bit positions of the target continuous bits and the bit number of the target continuous bits includes:
if the number of the high-order consecutive bits in the previous byte plus the number of the low-order consecutive bits in the current byte is greater than or equal to the required number of consecutive bits, the number of the target consecutive bits is equal to the number of the high-order consecutive bits in the previous byte plus the number of the low-order consecutive bits in the current byte, the high-order address bit position of the target consecutive bits is equal to the high-order address bit position of the previous byte plus the number of the low-order consecutive bits in the current byte, and when the current byte is the first byte of the index bitmap, the high-order address bit position of the previous byte is zero;
if the middle continuous maximum bit number in the current byte is greater than or equal to the required continuous bit number, the bit number of the target continuous bit is equal to the middle continuous maximum bit number in the current byte, and the high-order address bit position of the target continuous bit is equal to the high-order address bit position of the last byte plus the middle continuous maximum bit number in the current byte plus the low-order address offset of the continuous bit corresponding to the middle continuous maximum bit number in the current byte;
if the number of the high-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits, the number of the target continuous bits is equal to the number of the high-order continuous bits in the current byte, and the position of the high-order address bits of the target continuous bits is equal to the position of the high-order address bits of the previous byte plus eight.
From the above description, it can be known that, for different continuous conditions of low order, middle order and high order, the high order address bit position of the target continuous bit and the bit number of the target continuous bit are obtained, and the accuracy of obtaining the target continuous bit information can be ensured by classifying various conditions, so as to realize the optimal matching.
Further, the method also comprises the following steps:
and receiving a heap memory release request, and marking index bitmap bits corresponding to the address of the heap memory requested to be released by the first identification.
It can be known from the above description that the first identifier is used to mark the bit of the index bitmap corresponding to the memory address to be released, and the released heap memory address can be determined by looking up the table, thereby improving the memory management efficiency.
Referring to fig. 3, another embodiment of the present invention provides a heap memory management device, including:
the initialization module is used for establishing a continuous bit lookup table and establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
the allocation module is used for receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by using a second identification;
the first identifier is different from the second identifier.
Another embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of the heap memory management method described above.
Referring to fig. 4, another embodiment of the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the steps of the heap memory management method when executing the computer program.
The heap memory management method, the heap memory management device, the computer-readable storage medium and the electronic device of the present invention can be applied to various heap memory management environments, and can be applied to hardware for accelerated processing, and the following description is provided by specific embodiments:
example one
Referring to fig. 2, a heap memory management method includes the steps of:
establishing a continuous bit lookup table;
the continuous bit lookup table comprises the lower address offset of continuous bits corresponding to the lower continuous bit number, the upper continuous bit number, the middle continuous maximum bit number and the middle continuous maximum bit number;
the number of the low-order continuous bits is the number of the continuous bits of the first identifier from the low-order bits in the bit array with the preset length to be inquired;
the high-order continuous bit number is the continuous bit number of the first identifier from the high-order bit in the bit array with the preset length to be inquired;
the middle continuous maximum bit number is the maximum continuous bit number of the first identifier in a bit block with the second identifier at two ends and the first identifier in the middle in a bit array with preset length to be inquired;
wherein the first identifier is different from the second identifier;
specifically, in this embodiment, the first flag is 1, the second flag is 0, the number of consecutive lower bits is lowSeqCnt, the number of consecutive upper bits is highSeqCnt, the number of consecutive middle bits is midSeqCnt, and the lower address of the consecutive lower bits corresponding to the number of consecutive middle bits is midseqff, so bytes 0xA2, 0xFE, 0x3D, and 0x7C are taken as examples:
byte 0xA2 is binary 10100010, lowSeqCnt ═ 0, highSeqCnt ═ 1, midSeqCnt ═ 1, and midSeqOff ═ 1;
byte 0xFE has binary value of 11111110, lowSeqCnt ═ 0, highSeqCnt ═ 7, midSeqCnt ═ 0, and midSeqOff ═ 0;
byte 0x3D has a binary value of 00111101, lowSeqCnt ═ 1, highSeqCnt ═ 0, midSeqCnt ═ 4, and midSeqOff ═ 2;
byte 0x7C has a binary value of 01111100, lowSeqCnt ═ 0, highSeqCnt ═ 0, midSeqCnt ═ 5, and midSeqOff ═ 2;
establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
setting a preset memory size corresponding to one bit in the index bitmap;
calculating the byte number of the index bitmap according to the size of the heap memory to be managed and the size of the preset memory, and establishing the index bitmap according to the byte number;
specifically, in this embodiment, the managed heap memory size is 16kB, each bit is represented as 64Bytes, and the required managed memory is 16kB/64Bytes/8 ═ 32Bytes, so that an index bitmap is established according to the Bytes that need to be managed: u8 heapBitAlrray [32], that is, the index bitmap is an array, there are 32 elements in the array, and each element has 8 bits to represent a byte;
when the index bitmap is initialized, writing a first identifier into all values of the index bitmap, in this embodiment, initializing heapBitArray [32] to all 1, that is, 8 bits of each element are 1;
receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by a second identifier;
the size of the heap memory requested to be allocated is rounded according to the preset memory size;
calculating the number of continuous bits required by the size of the heap memory requested to be allocated;
according to the continuous bit lookup table, judging whether the continuous bit quantity of the target continuous bit with the value of the first identification in the current byte selected by the index bitmap meets the required continuous bit quantity, if so, acquiring the target continuous bit, and if not, performing the judgment on the next byte of the index bitmap until the target continuous bit meeting the required continuous bit quantity is found;
determining the address of the heap memory matched with the size of the heap memory according to the target continuous bit;
wherein obtaining the target sequential bits comprises: acquiring the high-order address bit position of the target continuous bit and the bit number of the target continuous bit;
the determining, according to the target continuous bits, an address of the heap memory that matches the size of the heap memory requested to be allocated includes:
determining the address of the heap memory matched with the size of the heap memory according to the high address bit position of the target continuous bit, the number of the target continuous bit and the preset memory size:
the address of the heap memory matched with the size of the heap memory requested to be allocated is the initial address of the heap memory + (the bit position of the high address of the inquired continuous bits-the number of the inquired continuous bits) and the size of the preset memory;
specifically, in this embodiment, the preset memory size is 64Bytes, the heap memory with the size of 190Bytes to be allocated is obtained by rounding the allocation size by 64, that is, 192, so that the required number of consecutive bits is 3 bits, starting from heapbitrreay [0] to search whether consecutive bits meeting 3 bits exist, if yes, obtaining the high-order address bit position endBitPos of the target consecutive bits and the searched bit number seqBitCnt of the target consecutive bits, if not, searching whether consecutive bits meeting 3 bits exist in heapbitrreay [1], and so on until the consecutive bits meeting the required number of consecutive bits are found;
the allocated heap memory address can be calculated according to the inquired endBitPos and seqBitCnt;
the allocated heap memory address is the initial heap memory address + (endBitPos-seqBitCnt) × 64 Bytes;
after the distribution is finished, writing the bit position of the heapBitAlrray index bitmap corresponding to the distribution part into 0;
and receiving a heap memory release request, and marking index bitmap bits corresponding to the address of the heap memory requested to be released by the first identification.
Specifically, the bits of the heapBitArray index bitmap corresponding to the release address and the length range are relabeled to 1.
Example two
The difference between this embodiment and the first embodiment is that how to find the target continuous bits meeting the requirement is defined:
judging whether the value of the number of continuous bits in the current byte selected by the index bitmap is the number of continuous bits which is required by the number of continuous bits of the target continuous bits of the first identifier comprises the following steps:
judging whether the number of the high-order continuous bits in the previous byte plus the number of the low-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits, when the current byte is the first byte of the index bitmap, the value of the number of the high-order continuous bits in the previous byte is zero, if so, determining that the number of the continuous bits having the target continuous bits with the value of the first identifier meets the required number of the continuous bits, and if not, judging whether the current byte is the first identifier;
if yes, adding eight to the number of the high-order continuous bits in the previous byte, entering the next byte, and returning to execute the operation of judging whether the number of the high-order continuous bits in the previous byte and the number of the low-order continuous bits in the current byte are more than or equal to the required number of the continuous bits, if not, judging whether the number of the middle continuous maximum bits in the current byte is more than or equal to the required number of the continuous bits;
if the number of the continuous bits of the target continuous bits with the value of the first identifier is greater than or equal to the required number of the continuous bits, determining whether the number of the high-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits;
if the number of the continuous bits of the target continuous bits with the value of the first identifier is larger than or equal to the required number of the continuous bits, determining that the number of the continuous bits with the value of the target continuous bits with the first identifier meets the required number of the continuous bits, if the number of the continuous bits with the value of the first identifier is smaller than the required number of the continuous bits, entering a next byte, and returning to the operation of judging whether the number of the high-order continuous bits in the previous byte and the number of the low-order continuous bits in the current byte are larger than or equal to the required number of the continuous bits or not until the target continuous bits meeting the;
acquiring the high address bit positions of the target continuous bits and the bit number of the target continuous bits comprises:
if the number of the high-order consecutive bits in the previous byte plus the number of the low-order consecutive bits in the current byte is greater than or equal to the required number of consecutive bits, the number of the target consecutive bits is equal to the number of the high-order consecutive bits in the previous byte plus the number of the low-order consecutive bits in the current byte, the high-order address bit position of the target consecutive bits is equal to the high-order address bit position of the previous byte plus the number of the low-order consecutive bits in the current byte, and when the current byte is the first byte of the index bitmap, the high-order address bit position of the previous byte is zero;
if the middle continuous maximum bit number in the current byte is greater than or equal to the required continuous bit number, the bit number of the target continuous bit is equal to the middle continuous maximum bit number in the current byte, and the high-order address bit position of the target continuous bit is equal to the high-order address bit position of the last byte plus the middle continuous maximum bit number in the current byte plus the low-order address offset of the continuous bit corresponding to the middle continuous maximum bit number in the current byte;
if the number of the high-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits, the number of the target continuous bits is equal to the number of the high-order continuous bits in the current byte, and the position of the high-order address bits of the target continuous bits is equal to the position of the high-order address bits of the previous byte plus eight;
specifically, in this embodiment, the size of the heap memory to be managed is 2kB, and each bit is represented by 64Bytes, so that 2kB/64Bytes/8 ═ 4Bytes can be obtained through calculation, that is, the index bitmap is defined as: u8 heapbitarry [4], initializes the index bitmap, i.e., heapbitarry [0] ═ 11111111, heapbitarry [1] ═ 11111111, heapbitarry [2] ═ 11111111111111, heapbitarry [3] ═ 11111111111111111, and in the initial case, the number of high-order consecutive bits in the last byte, prebytesequnt ═ 0;
a heap memory of 60Bytes needs to be allocated, that is, the bit bits needing to be allocated are 1 bit, at this time, preByteSeqCnt + lowSeqCnt in heapbitraray [0] is greater than 1, so that the lower bits have satisfied target continuous bits, endBitPos is 8, seqBitCnt is 8, and thus the flag of heapbitraray [0] is 11111110;
a heap memory of 90Bytes needs to be allocated, that is, the bit bits to be allocated are 2 bits, at this time, highSeqCnt in heapbitraray [0] is 7 and is greater than 1, so that the upper bits have satisfied target continuous bits, and endBitPos is 8 and seqBitCnt is 7, so that the heapbitraray [0] is marked as 11111000;
a heap memory of 130Bytes needs to be allocated, that is, the bit bits to be allocated are 3 bits, at this time, highSeqCnt in heapbitraray [0] is 5 and is greater than 1, so that the upper bits have satisfied target continuous bits, and endBitPos is 8 and seqBitCnt is 5, so that the tag of heapbitraray [0] is 11000000;
heap memory that was allocated 90Bytes before it needs to be freed, so hapBitAlrray [0] is labeled 11000110;
a heap memory of 60Bytes needs to be allocated, that is, the bit bits needing to be allocated are 1 bit, at this time, midSeqCnt ═ 2, midSeqOff ═ 1, and midSeqCnt greater than 1 in heapbitrray [0], so that there are satisfied target continuous bits in the middle, and endBitPos ═ 3 and seqBitCnt ═ 2 are obtained, so that the label of heapbitrray [0] is 11000100;
the heap memory of 800Bytes needs to be allocated, that is, the bits that need to be allocated are 13 bits, and there are no consecutive bits that satisfy the requirement in heapbitarry [0] at this time, so prebytesqcnt + lowSeqCnt of [1] is 10, and is less than 13, so prebytesqcnt +8 is 10, endBitPos +8 is 16, and enters heapbitrray [2], so prebytesqcnt + lowSeqCnt of heapbitrray [2] is 18, and is greater than 13, so there are target consecutive bits that satisfy in the low bits, resulting in biendops +8 being 24, setbistatic +8 being 18, and thus, heapbitzergt +8 being 3500000, and being labeled as [ 000000000 ] for heapbitaprcurry [ 00002 ].
EXAMPLE III
Referring to fig. 3, a heap memory management apparatus includes:
the initialization module is used for establishing a continuous bit lookup table and establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
the allocation module is used for receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by using a second identification;
the first identifier is different from the second identifier.
Example four
A computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the steps in a heap memory management method according to any one of the first to second embodiments.
EXAMPLE five
Referring to fig. 4, an electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the steps of the heap memory management method according to any one of the first to second embodiments.
In summary, according to the heap memory management method, the apparatus, the readable storage medium and the electronic device provided by the present invention, for the heap memory to be allocated, the allocation address of the heap memory to be allocated is inquired by establishing the continuous bit inquiry table and the index bitmap, and the corresponding index bitmap bit is marked by the second identifier, wherein each byte in the index bitmap is inquired, so that the continuous bit meeting the requirement can be conveniently and quickly located, whether the low order, the middle order and the high order of each byte have the continuous bit meeting the requirement is sequentially judged, and when the low order is compared, the low order continuous bit of the current byte is compared with the high order continuous bit of one byte, so as to avoid missing in searching, and realize the optimal matching; the method has obvious advantages in typical scenes, such as when the distributed size is integral multiple of 64Bytes, so that the method can determine the heap memory address to be distributed and released by table look-up without merging and splitting the heap memory, can improve the memory management efficiency, does not need to operate a linked list, is only simple table look-up operation, is convenient to apply to hardware for accelerated processing, and is more beneficial to performance improvement.
In the above embodiments provided in the present application, it should be understood that the disclosed method, apparatus, computer-readable storage medium, and electronic device may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical division, and other divisions may be realized in practice, for example, a plurality of components or modules may be combined or integrated into another apparatus, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or components or modules, and may be in an electrical, mechanical or other form.
The components described as separate parts may or may not be physically separate, and parts displayed as components may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the components can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing module, or each component may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode.
The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It should be noted that, for the sake of simplicity, the above-mentioned method embodiments are described as a series of acts or combinations, but those skilled in the art should understand that the present invention is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no acts or modules are necessarily required of the invention.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (10)

1. A heap memory management method is characterized by comprising the following steps:
establishing a continuous bit lookup table;
establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by a second identifier;
the first identifier is different from the second identifier.
2. The heap memory management method according to claim 1, wherein the establishing of the index bitmap according to the size of the heap memory to be managed comprises:
setting a preset memory size corresponding to one bit in the index bitmap;
calculating the byte number of the index bitmap according to the size of the heap memory to be managed and the size of the preset memory;
and establishing the index bitmap according to the byte number.
3. The heap memory management method of claim 2, wherein the determining the address of the heap memory matching the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated comprises:
rounding the size of the heap memory requested to be allocated according to the preset memory size;
calculating the number of continuous bits required by the size of the heap memory requested to be allocated;
according to the continuous bit lookup table, judging whether the continuous bit quantity of the target continuous bit with the value of the first identification in the current byte selected by the index bitmap meets the required continuous bit quantity, if so, acquiring the target continuous bit, and if not, performing the judgment on the next byte of the index bitmap until the target continuous bit meeting the required continuous bit quantity is found;
and determining the address of the heap memory matched with the size of the heap memory according to the target continuous bit.
4. The heap memory management method of claim 3 wherein the sequential bit lookup table includes a number of lower sequential bits, a number of upper sequential bits, and a middle sequential maximum number of bits;
the number of the low-order continuous bits is the number of the continuous bits of the first identifier from the low-order bits in the bit array with the preset length to be inquired;
the high-order continuous bit number is the continuous bit number of the first identifier from the high-order bit in the bit array with the preset length to be inquired;
the middle continuous maximum bit number is the maximum continuous bit number of the first identifier in a bit block with the second identifier at two ends and the first identifier in the middle in a bit array with preset length to be inquired;
the determining whether the number of consecutive bits having a value that satisfies the required number of consecutive bits of the target consecutive bits of the first identifier exists in the current byte selected by the index bitmap includes:
judging whether the number of the high-order continuous bits in the previous byte plus the number of the low-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits, when the current byte is the first byte of the index bitmap, the value of the number of the high-order continuous bits in the previous byte is zero, if so, determining that the number of the continuous bits having the target continuous bits with the value of the first identifier meets the required number of the continuous bits, and if not, judging whether the current byte is the first identifier;
if yes, adding eight to the number of the high-order continuous bits in the previous byte, entering the next byte, and returning to execute the operation of judging whether the number of the high-order continuous bits in the previous byte and the number of the low-order continuous bits in the current byte are more than or equal to the required number of the continuous bits, if not, judging whether the number of the middle continuous maximum bits in the current byte is more than or equal to the required number of the continuous bits;
if the number of the continuous bits of the target continuous bits with the value of the first identifier is greater than or equal to the required number of the continuous bits, determining whether the number of the high-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits;
if the number of the continuous bits is larger than or equal to the required number of the continuous bits, determining that the number of the continuous bits with the value of the target continuous bits of the first identifier meets the required number of the continuous bits, if the number of the continuous bits is smaller than the required number of the continuous bits, entering the next byte, and returning to execute the operation of judging whether the number of the high-order continuous bits in the previous byte and the number of the low-order continuous bits in the current byte are larger than or equal to the required number of the continuous bits until the target continuous bits meeting the required number of the continuous bits are found.
5. The heap memory management method of claim 4, wherein said obtaining the target sequential bits comprises:
acquiring the high-order address bit position of the target continuous bit and the bit number of the target continuous bit;
the determining, according to the target continuous bits, an address of the heap memory that matches the size of the heap memory requested to be allocated includes:
determining the address of the heap memory matched with the size of the heap memory according to the high address bit position of the target continuous bit, the number of the target continuous bit and the preset memory size:
the address of the heap memory matched with the size of the heap memory requested to be allocated is the starting address of the heap memory + (the upper address bit position of the inquired continuous bits-the inquired continuous bit number) and the size of the preset memory.
6. The heap memory management method of claim 5 wherein the sequential bit lookup table further includes a lower address offset of sequential bits corresponding to the intermediate sequential maximum number of bits;
the obtaining the upper address bit positions of the target continuous bits and the bit number of the target continuous bits includes:
if the number of the high-order consecutive bits in the previous byte plus the number of the low-order consecutive bits in the current byte is greater than or equal to the required number of consecutive bits, the number of the target consecutive bits is equal to the number of the high-order consecutive bits in the previous byte plus the number of the low-order consecutive bits in the current byte, the high-order address bit position of the target consecutive bits is equal to the high-order address bit position of the previous byte plus the number of the low-order consecutive bits in the current byte, and when the current byte is the first byte of the index bitmap, the high-order address bit position of the previous byte is zero;
if the middle continuous maximum bit number in the current byte is greater than or equal to the required continuous bit number, the bit number of the target continuous bit is equal to the middle continuous maximum bit number in the current byte, and the high-order address bit position of the target continuous bit is equal to the high-order address bit position of the last byte plus the middle continuous maximum bit number in the current byte plus the low-order address offset of the continuous bit corresponding to the middle continuous maximum bit number in the current byte;
if the number of the high-order continuous bits in the current byte is greater than or equal to the required number of the continuous bits, the number of the target continuous bits is equal to the number of the high-order continuous bits in the current byte, and the position of the high-order address bits of the target continuous bits is equal to the position of the high-order address bits of the previous byte plus eight.
7. The heap memory management method according to any of claims 1 to 6, further comprising the steps of:
and receiving a heap memory release request, and marking index bitmap bits corresponding to the address of the heap memory requested to be released by the first identification.
8. A heap memory management apparatus, comprising:
the initialization module is used for establishing a continuous bit lookup table and establishing an index bitmap according to the size of a heap memory to be managed, wherein the initial value of each bit of the index bitmap is a first identifier;
the allocation module is used for receiving a heap memory allocation request, determining the address of the heap memory matched with the size of the heap memory requested to be allocated according to the continuous bit lookup table, the index bitmap and the size of the heap memory requested to be allocated, and marking the bit of the index bitmap corresponding to the address of the heap memory requested to be allocated by using a second identification;
the first identifier is different from the second identifier.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the heap memory management method according to any one of claims 1 to 7.
10. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the heap memory management method according to any one of claims 1 to 7 when executing the computer program.
CN202011508383.5A 2020-12-18 2020-12-18 Heap memory management method and device, readable storage medium and electronic equipment Active CN112667152B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011508383.5A CN112667152B (en) 2020-12-18 2020-12-18 Heap memory management method and device, readable storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011508383.5A CN112667152B (en) 2020-12-18 2020-12-18 Heap memory management method and device, readable storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN112667152A true CN112667152A (en) 2021-04-16
CN112667152B CN112667152B (en) 2023-04-07

Family

ID=75406980

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011508383.5A Active CN112667152B (en) 2020-12-18 2020-12-18 Heap memory management method and device, readable storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN112667152B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113268349A (en) * 2021-06-04 2021-08-17 科东(广州)软件科技有限公司 Computer memory management method, device, equipment and storage medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5784699A (en) * 1996-05-24 1998-07-21 Oracle Corporation Dynamic memory allocation in a computer using a bit map index
US5920876A (en) * 1997-04-23 1999-07-06 Sun Microsystems, Inc. Performing exact garbage collection using bitmaps that identify pointer values within objects
US20050278487A1 (en) * 2004-06-04 2005-12-15 International Business Machines Corporation Efficient parallel bitwise sweep during garbage collection
US20090094589A1 (en) * 2007-10-04 2009-04-09 Satish Chandra Gupta Optimizing heap memory usage
CN102541758A (en) * 2011-12-22 2012-07-04 深圳市融创天下科技股份有限公司 Method, system as well as terminal equipment for allocating and releasing memory
US20140089625A1 (en) * 2012-09-26 2014-03-27 Avaya, Inc. Method for Heap Management
CN110780823A (en) * 2019-11-06 2020-02-11 广东三维家信息科技有限公司 Small object memory management method and device, electronic equipment and computer readable medium
CN111984401A (en) * 2020-07-24 2020-11-24 五八有限公司 Memory overflow management method and device, electronic equipment and storage medium
CN112052193A (en) * 2020-09-28 2020-12-08 成都佰维存储科技有限公司 Garbage recycling method and device, readable storage medium and electronic equipment

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5784699A (en) * 1996-05-24 1998-07-21 Oracle Corporation Dynamic memory allocation in a computer using a bit map index
US5920876A (en) * 1997-04-23 1999-07-06 Sun Microsystems, Inc. Performing exact garbage collection using bitmaps that identify pointer values within objects
US20050278487A1 (en) * 2004-06-04 2005-12-15 International Business Machines Corporation Efficient parallel bitwise sweep during garbage collection
US20090094589A1 (en) * 2007-10-04 2009-04-09 Satish Chandra Gupta Optimizing heap memory usage
CN102541758A (en) * 2011-12-22 2012-07-04 深圳市融创天下科技股份有限公司 Method, system as well as terminal equipment for allocating and releasing memory
US20140089625A1 (en) * 2012-09-26 2014-03-27 Avaya, Inc. Method for Heap Management
CN110780823A (en) * 2019-11-06 2020-02-11 广东三维家信息科技有限公司 Small object memory management method and device, electronic equipment and computer readable medium
CN111984401A (en) * 2020-07-24 2020-11-24 五八有限公司 Memory overflow management method and device, electronic equipment and storage medium
CN112052193A (en) * 2020-09-28 2020-12-08 成都佰维存储科技有限公司 Garbage recycling method and device, readable storage medium and electronic equipment

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
HONGWEI LI 等: ""Analysis and Improvement of RTEMS Memory Management"", 《2009 FIRST INTERNATIONAL WORKSHOP ON EDUCATION TECHNOLOGY AND COMPUTER SCIENCE》 *
刘林 等: ""FreeRTOS内存管理方案的分析与改进"", 《计算机工程与应用》 *
胡雨翠: ""嵌入式实时系统ARTs-OS的动态内存管理研究"", 《万方数据》 *
陈君 等: ""基于TLSF算法改进的动态内存管理算法研究"", 《网络新媒体技术》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113268349A (en) * 2021-06-04 2021-08-17 科东(广州)软件科技有限公司 Computer memory management method, device, equipment and storage medium
CN113268349B (en) * 2021-06-04 2022-02-18 科东(广州)软件科技有限公司 Computer memory management method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN112667152B (en) 2023-04-07

Similar Documents

Publication Publication Date Title
CN108255958B (en) Data query method, device and storage medium
CN106874348B (en) File storage and index method and device and file reading method
RU2005105582A (en) DATABASE AND KNOWLEDGE MANAGEMENT SYSTEM
CN102024046B (en) Data repeatability checking method and device as well as system
CN113612705B (en) Hash algorithm slicing and recombination-based power grid monitoring system data transmission method
CN111859033B (en) IP library query method and device and IP library compression method and device
CN114721972B (en) Garbage recycling method and device, readable storage medium and electronic equipment
CN105589894A (en) Document index establishing method and device as well as document retrieving method and device
CN113835639B (en) I/O request processing method, device, equipment and readable storage medium
CN112667152B (en) Heap memory management method and device, readable storage medium and electronic equipment
CN110134335A (en) A kind of RDF data management method, device and storage medium based on key-value pair
CN112800067B (en) Range query method, range query device, computer-readable storage medium and electronic device
CN112069175A (en) Data query method and device and electronic equipment
CN110674052A (en) Memory management method, server and readable storage medium
CN113111227A (en) Data processing method and device, electronic equipment and storage medium
CN110825953B (en) Data query method, device and equipment
CN109739854A (en) A kind of date storage method and device
CN110008030A (en) A kind of method of metadata access, system and equipment
CN111966846B (en) Image query method, device, electronic equipment and storage medium
CN112799972A (en) Implementation method and device of SSD mapping table, readable storage medium and electronic equipment
CN112685417A (en) Database operation method, system, device, server and storage medium
CN112783971A (en) Transaction recording method, transaction query method, electronic device and storage medium
CN111026762A (en) Red and black tree index generation method and device, electronic equipment and storage medium
US11507293B2 (en) Method, electronic device and computer program product for managing storage blocks
US20190227726A1 (en) Disk-image deduplication with hash subset in memory

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
GR01 Patent grant