CN111104347B - Heap memory block searching method, device, equipment and storage medium - Google Patents

Heap memory block searching method, device, equipment and storage medium Download PDF

Info

Publication number
CN111104347B
CN111104347B CN201911341124.5A CN201911341124A CN111104347B CN 111104347 B CN111104347 B CN 111104347B CN 201911341124 A CN201911341124 A CN 201911341124A CN 111104347 B CN111104347 B CN 111104347B
Authority
CN
China
Prior art keywords
memory
mapping
address
memory block
heap
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
CN201911341124.5A
Other languages
Chinese (zh)
Other versions
CN111104347A (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.)
Beijing Armyfly Technology Co Ltd
Original Assignee
Beijing Armyfly 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 Beijing Armyfly Technology Co Ltd filed Critical Beijing Armyfly Technology Co Ltd
Priority to CN201911341124.5A priority Critical patent/CN111104347B/en
Publication of CN111104347A publication Critical patent/CN111104347A/en
Application granted granted Critical
Publication of CN111104347B publication Critical patent/CN111104347B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The embodiment of the invention discloses a method, a device and equipment for searching a heap memory block and a storage medium. The method is applied to an embedded system and comprises the following steps: acquiring a target memory address, and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element; acquiring a heap memory block initial address corresponding to the subscript value from the mapping array; and if the target memory address belongs to the memory address range corresponding to the head address of the heap memory block, determining the heap memory block corresponding to the head address of the heap memory block as a target heap memory block matched with the target memory address. The technical scheme of the embodiment of the invention realizes that the heap memory blocks in the memory block linked list can be quickly positioned to any memory address in the heap memory range in the embedded system through address resolution calculation.

Description

Heap memory block searching method, device, equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a method, a device, equipment and a storage medium for searching a heap memory block.
Background
In an existing embedded system, a heap memory block is generally allocated from a system heap by using a function such as malloc, and a head address of the allocated heap memory block is returned by using the malloc function, so that an attribute of the heap memory block can be checked. However, when a system error is reported or a programmer operates the system, since the acquired address is not necessarily an address returned by the malloc, a professional needs to search the heap memory block corresponding to the address from a large number of heap memory addresses through the assembly code first to check the attribute of the memory block.
The existing heap memory block searching method comprises the following steps: setting the heap memory blocks in the system to be fixed in size, establishing a one-to-one mapping relation between each heap memory block and each subscript of the management array, finding the corresponding subscript in the management array according to the designated address of the heap memory block, and finding the heap memory block to be found according to the subscript. However, the heap memory block searching method requires that the heap memory block has to be a fixed size, which is not beneficial to flexible allocation of the memory, and the corresponding heap memory block can only be found according to a specified memory address, and the heap memory block corresponding to any memory address cannot be found.
Disclosure of Invention
The embodiment of the invention provides a heap memory block searching method, a device, equipment and a storage medium, which are used for realizing that any memory address in a heap memory range in an embedded system can be quickly positioned to a heap memory block in a memory block linked list through address resolution calculation.
In a first aspect, an embodiment of the present invention provides a method for searching a heap memory block, which is applied to an embedded system, and includes:
acquiring a target memory address, and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
acquiring a heap memory block initial address corresponding to the subscript value from the mapping array;
and if the target memory address belongs to the memory address range corresponding to the head address of the heap memory block, determining the heap memory block corresponding to the head address of the heap memory block as a target heap memory block matched with the target memory address.
Optionally, calculating a subscript value of the mapping array corresponding to the target memory address includes:
according to a first formula:
Figure GDA0003363124710000021
calculating subscript values of mapping arrays corresponding to the target memory addresses;
wherein the operation sign
Figure GDA0003363124710000022
Indicating a ceiling operation.
Optionally, before obtaining the target memory address and calculating the subscript value of the mapping array corresponding to the target memory address, the method further includes:
equally dividing the heap memories into mapping memories with fixed sizes, wherein the size of the mapping memories is larger than or equal to the size of the minimum heap memory block;
calculating the memory size of the mapping array according to the heap memory size and the mapping memory size;
distributing corresponding memories for the mapping arrays according to the memory sizes of the mapping arrays;
traversing each heap memory block in the memory block linked list of the heap, and initializing the mapping array;
the size of each heap memory block is not fixed, and one mapping memory at least corresponds to one heap memory block.
Optionally, calculating the memory size of the mapping array according to the heap memory size and the mapping memory size includes:
determining the memory size of each array element of the mapping array according to the system address bit width;
according to a second formula: and calculating the memory size of the mapping array, namely the size of the heap memory/the size of the mapping memory, namely the size of the array elements.
Optionally, traversing each heap memory block in the memory block linked list of the heap, and initializing the mapping array, including:
calculating a starting subscript of a mapping array corresponding to a head address of the current heap memory block and an ending subscript of the mapping array corresponding to a tail address according to a first formula;
updating array elements between the starting subscript and the ending subscript of the mapping array by using the head address of the current heap memory block;
and updating the current heap memory block, and returning to execute the operation of calculating the starting subscript of the mapping array corresponding to the head address and the ending subscript of the mapping array corresponding to the tail address of the current heap memory block according to the first formula until all heap memory blocks in the heap memory block linked list are mapped.
Optionally, the method further includes:
when detecting the operation of allocating the memory or releasing the memory, judging whether a new memory heap block is generated;
and if so, updating the mapping array according to the head address and the tail address of each new heap memory block.
Optionally, after obtaining the memory block head address corresponding to the subscript value from the mapping array, the method further includes:
and if the target memory address does not belong to the memory address range corresponding to the heap memory block head address, traversing other heap memory blocks in the heap memory block linked list from the heap memory block head address according to the direction that the memory address becomes smaller so as to find out the target heap memory block matched with the target memory address.
In a second aspect, an embodiment of the present invention further provides a heap memory block search device, which is applied to an embedded system, and includes:
the calculation module is used for acquiring a target memory address and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
the obtaining module is used for obtaining the heap memory block head address corresponding to the subscript value from the mapping array;
and the judging module is used for determining that the heap memory block corresponding to the head address of the heap memory block is a target heap memory block matched with the target memory address if the target memory address belongs to the memory address range corresponding to the head address of the heap memory block.
In a third aspect, an embodiment of the present invention further provides an apparatus, which is applied to an embedded system, where the apparatus includes:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the heap memory block lookup method provided by any embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the heap memory block lookup method provided in any embodiment of the present invention.
The technical scheme of the embodiment of the invention is applied to an embedded system, and the subscript value of the mapping array corresponding to the target memory address is calculated by acquiring the target memory address; acquiring a heap memory block initial address corresponding to the subscript value from the mapping array; if the target memory address belongs to the memory address range corresponding to the heap memory block head address, determining that the heap memory block corresponding to the heap memory block head address is the target heap memory block matched with the target memory address, solving the problem that the heap memory block can only be searched under the condition that the size of the heap memory block is fixed and the appointed memory address of the heap memory block to be searched is known in the prior art, and realizing that the heap memory block in the heap memory block linked list can be quickly positioned by address resolution calculation for any memory address in the heap memory range in the embedded system.
Drawings
Fig. 1a is a flowchart of a heap memory block lookup method according to a first embodiment of the present invention;
fig. 1b is a schematic diagram illustrating a correspondence relationship between a heap memory block and a mapping array according to a first embodiment of the present invention;
fig. 1c is a schematic diagram illustrating an update of a heap memory block according to a first embodiment of the present invention;
fig. 2 is a schematic structural diagram of a heap memory block search device according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of an apparatus in a third embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1a is a flowchart of a heap memory block lookup method according to a first embodiment of the present invention, where this embodiment is applicable to a case where a corresponding heap memory block is looked up according to any heap memory address in an embedded system, and the method may be executed by a heap memory block lookup apparatus, where the apparatus may be implemented by hardware and/or software, and may generally be integrated in a device providing a heap memory block lookup service. As shown in fig. 1a, the method comprises:
step 110, obtaining the target memory address, and calculating a subscript value of the mapping array corresponding to the target memory address.
In this embodiment, the target memory address may be any memory address in the whole heap memory range, each array element of the mapping array corresponds to a mapping memory of a fixed size, and each array element stores the head address of the heap memory block including the tail address of the mapping memory corresponding to the head address.
Each heap memory block included in the heap memory is sequentially stored in the linked list according to the size of the memory address, the size of each heap memory block is not necessarily the same, the size of the mapping memory is not necessarily the same as that of the heap memory block, the address range of one mapping memory may span multiple heap memory blocks, and the address range of one heap memory block may span multiple mapping memories. The array element of the mapping array stores the maximum address of the mapping memory corresponding to the mapping array element, namely the tail address, and the head address of the heap memory block where the mapping memory is located. The attribute information of the heap memory block, such as the size of the heap memory block, the start address of the heap memory block, and the end address of the heap memory block, may be obtained according to the head address of the heap memory block.
For example, as shown in fig. 1b, the address range of the heap memory block 1 spans over the mapping memory 1, the mapping memory 2, and the mapping memory 3, where the mapping memories 1, 2, and 3 respectively correspond to array elements with subscripts of 1, 2, and 3 in the mapping array in a one-to-one manner, because the array elements of the mapping array store the head address of the heap memory block where the maximum address of the mapping memory corresponding to the array elements is located, the array elements with subscripts of 1 and 2 store the head address of the heap memory block 1, and the array elements with subscript of 3 store the head address of the heap memory block 2, that is, different array elements may correspond to the head address of the same heap memory block. For another example, the address range of the mapping memory 5 corresponding to the array element with the index 5 spans over the heap memory blocks 2, 3, and 4, but since the tail address of the mapping memory 5 falls within the address range of the heap memory block 4, the head address of the heap memory block 4 is stored in the array element 5, and it can be seen that the head address of the heap memory block 3 is not stored in the mapping array at this time.
Optionally, calculating the subscript value of the mapping array corresponding to the target memory address may include: according to a first formula:
Figure GDA0003363124710000071
calculating subscript values of mapping arrays corresponding to the target memory addresses; wherein the operation sign
Figure GDA0003363124710000074
Indicating a ceiling operation.
In this embodiment, each subscript value of the mapping array corresponds to one mapping memory, and the subscript value is consistent with the sequence number in the heap memory in the corresponding mapping, so that the subscript value of the mapping array corresponding to the target memory address can be determined as long as the number of the mapping memory to which the target memory address belongs is determined.
Specifically, the number of complete mapping memories included between the heap start address and the target memory address may be calculated first, at this time, if the target memory address is exactly the tail address of the included last mapping memory, the sequence number of the included last mapping memory is the required subscript value, and if the target memory address falls behind the included last mapping memory, the sequence number of the included first mapping memory behind the included last mapping memory is the required subscript value. It can be seen that, according to the formula:
Figure GDA0003363124710000072
Figure GDA0003363124710000073
the desired subscript value is obtained.
For example, as shown in fig. 1b, for a target memory address C in the heap memory block 2, the subscript value of the mapping array corresponding to the target memory address C is calculated according to the first formula to be 3.
Optionally, before obtaining the target memory address and calculating the subscript value of the mapping array corresponding to the target memory address, the method may further include: equally dividing the heap memories into mapping memories with fixed sizes, wherein the size of the mapping memories is larger than or equal to the size of the minimum heap memory block; calculating the memory size of the mapping array according to the heap memory size and the mapping memory size; distributing corresponding memories for the mapping arrays according to the memory sizes of the mapping arrays; traversing each heap memory block in the memory block linked list of the heap, and initializing the mapping array; the size of each heap memory block is not fixed, and one mapping memory at least corresponds to one heap memory block.
In this embodiment, in order to find the heap memory block corresponding to the target memory address when the sizes of the heap memory blocks are different, the entire heap memory is divided into a plurality of mapping memories of fixed sizes, and a mapping relationship between the heap memory block and the mapping array is established by the mapping memories, so that a search range of the target memory address can be reduced to an address range of a certain mapping memory. The size of the mapping memory determines the lookup efficiency of the heap memory block and the memory size of the mapping array, the smaller the mapping memory is, the higher the lookup efficiency is, the larger the mapping table memory is, and the size of the mapping memory in this embodiment is greater than or equal to the size of the minimum heap memory block.
Optionally, calculating the memory size of the mapping array according to the heap memory size and the mapping memory size may include: determining the memory size of each array element of the mapping array according to the system address bit width; according to a second formula: and calculating the memory size of the mapping array, namely the size of the heap memory/the size of the mapping memory, namely the size of the array elements.
In this embodiment, the memory size of each array element is related to the system address bit width, and if the system address bit width is 32 bits, the array element is an int type, and the memory size of the array element is 4 bytes; if the system address bit width is 64 bits, the array element is of long type, and the memory size of the array element is 8 bytes.
For example, as shown in fig. 1b, assuming that the mapping memory size is 256 bytes, the heap memory size is 700M, and the mapping array is an int-type array, that is, the memory size of each array element is 4 bytes, then the memory size of the mapping array is 700M/256 × 4 — 11468800 bytes.
Optionally, traversing each heap memory block in the heap memory block linked list, and initializing the mapping array may include: calculating a starting subscript of a mapping array corresponding to a head address of the current heap memory block and an ending subscript of the mapping array corresponding to a tail address according to a first formula; updating array elements between the starting subscript and the ending subscript of the mapping array by using the head address of the current heap memory block; and updating the current heap memory block, and returning to execute the operation of calculating the starting subscript of the mapping array corresponding to the head address and the ending subscript of the mapping array corresponding to the tail address of the current heap memory block according to the first formula until all heap memory blocks in the heap memory block linked list are mapped.
In this embodiment, the initialization of the mapping array occurs when the first memory block is initialized, and when the addresses of the two heap memory blocks correspond to the same mapping memory, that is, correspond to the same array element, the last address of the heap memory block with a larger address is stored in the array element.
Optionally, the method may further include: when detecting the operation of allocating the memory or releasing the memory, judging whether a new memory heap block is generated; and if so, updating the mapping array according to the head address and the tail address of each new heap memory block.
In this embodiment, when the malloc function is called to allocate the heap memory blocks, since the size of the heap memory blocks to be allocated may not be consistent with the size of the idle heap memory blocks in the heap memory, a certain idle heap memory block may need to be split, which causes the number of the heap memory blocks included in the heap memory block linked list to change, that is, a new heap memory block is generated, or when the free function is called to release the heap memory block, in order to avoid generation of memory fragments, the released heap memory block needs to be merged with the previous and next idle heap memory blocks, which causes the number of the heap memory blocks included in the heap memory block linked list to change, that is, a new heap memory block is generated. The new heap memory block may be a plurality of heap memory blocks obtained by splitting the heap memory blocks in the original memory block linked list, or a heap memory block generated after combining at least two heap memory blocks in the original memory block linked list.
When the number of the heap memory blocks in the memory block linked list changes, that is, a new heap memory block is generated, the start subscript of the mapping array corresponding to the head address of the new heap memory block and the end subscript of the mapping array corresponding to the tail address are respectively calculated according to a first formula, then whether the head address of the heap memory block is stored in the array element to be updated between the start subscript and the end subscript of the mapping array is judged, if not, the head address of the new heap memory block is stored in the corresponding array element to be updated, if so, whether the head address of the new heap memory block is larger than the head address of the heap memory block in the array element to be updated is judged, if so, the array element to be updated is updated according to the head address of the new heap memory block, otherwise, the array element to be updated is not updated. In this embodiment, only the first address of the heap memory block corresponding to the maximum memory address of the mapped memory is stored in the mapped array, so as to avoid the problem that the array subscript calculated according to the memory address conflicts.
For example, as shown in fig. 1c, when the heap memory block 1 in fig. 1b is split into the heap memory block 1.1 and the heap memory block 1.2, it is necessary to update an array element with a subscript value of 1 in the mapping array as the head address of the heap memory block 1.1, and update an array element with a subscript value of 2 as the head address of the heap memory block 1.2; when the heap memory block 3 and the heap memory block 4 in fig. 1b are merged into the heap memory block 34, the array elements with index values of 5 and 6 need to be updated as the head address of the heap memory block 34.
And step 120, acquiring the heap memory block head address corresponding to the subscript value from the mapping array.
In this embodiment, according to the mapping relationship between the subscript value of each array element in the mapping array and the heap memory block, when the subscript value of the mapping array corresponding to the target memory address is determined, the heap memory block header address corresponding to the subscript value may be obtained from the mapping array.
Step 130, if the target memory address belongs to the memory address range corresponding to the heap memory block head address, determining that the heap memory block corresponding to the heap memory block head address is the target heap memory block matched with the target memory address.
Optionally, after obtaining the memory block head address corresponding to the subscript value from the mapping array, the method may further include: and if the target memory address does not belong to the memory address range corresponding to the heap memory block head address, traversing other heap memory blocks in the heap memory block linked list from the heap memory block head address according to the direction that the memory address becomes smaller so as to find out the target heap memory block matched with the target memory address.
In this embodiment, a target memory address is compared with a memory address range corresponding to an obtained heap memory block head address, and whether the obtained heap memory block head address is the head address of the target heap memory block is determined, if not, the target heap memory block can be found by comparing at most n heap memory blocks from the obtained heap memory block head address in a direction in which the memory address becomes smaller, where the maximum number of comparison times n is a quotient integer obtained by dividing the size of the mapped memory by the size of the minimum heap memory block, that is, the maximum number of the heap memory blocks corresponding to the mapped memory.
The technical scheme of the embodiment of the invention is applied to an embedded system, and the subscript value of the mapping array corresponding to the target memory address is calculated by acquiring the target memory address; acquiring a heap memory block initial address corresponding to the subscript value from the mapping array; if the target memory address belongs to the memory address range corresponding to the heap memory block head address, determining that the heap memory block corresponding to the heap memory block head address is the target heap memory block matched with the target memory address, solving the problem that the heap memory block can only be searched under the condition that the size of the heap memory block is fixed and the appointed memory address of the heap memory block to be searched is known in the prior art, and realizing that the heap memory block in the heap memory block linked list can be quickly positioned by address resolution calculation for any memory address in the heap memory range in the embedded system.
Example two
Fig. 2 is a schematic structural diagram of a heap memory block search apparatus according to a second embodiment of the present invention, which is applicable to a case where a corresponding heap memory block is searched according to any heap memory address in an embedded system. As shown in fig. 2, the heap memory block search apparatus includes:
a calculating module 210, configured to obtain a target memory address, and calculate a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
an obtaining module 220, configured to obtain a heap memory block head address corresponding to the subscript value from the mapping array;
the determining module 230 is configured to determine, if the target memory address belongs to the memory address range corresponding to the heap memory block head address, that the heap memory block corresponding to the heap memory block head address is a target heap memory block matched with the target memory address.
The technical scheme of the embodiment of the invention is applied to an embedded system, and the subscript value of the mapping array corresponding to the target memory address is calculated by acquiring the target memory address; acquiring a heap memory block initial address corresponding to the subscript value from the mapping array; if the target memory address belongs to the memory address range corresponding to the heap memory block head address, determining that the heap memory block corresponding to the heap memory block head address is the target heap memory block matched with the target memory address, solving the problem that the heap memory block can only be searched under the condition that the size of the heap memory block is fixed and the appointed memory address of the heap memory block to be searched is known in the prior art, and realizing that the heap memory block in the heap memory block linked list can be quickly positioned by address resolution calculation for any memory address in the heap memory range in the embedded system.
Optionally, the calculating module 210 is specifically configured to: according to a first formula:
Figure GDA0003363124710000121
Figure GDA0003363124710000122
calculating subscript values of mapping arrays corresponding to the target memory addresses; wherein the operation sign
Figure GDA0003363124710000123
Indicating a ceiling operation.
Optionally, the method further includes: the array initialization module is used for equally dividing the heap memory into mapping memories with fixed sizes before acquiring a target memory address and calculating a subscript value of a mapping array corresponding to the target memory address, wherein the size of the mapping memory is larger than or equal to the size of a minimum heap memory block; calculating the memory size of the mapping array according to the heap memory size and the mapping memory size; distributing corresponding memories for the mapping arrays according to the memory sizes of the mapping arrays; traversing each heap memory block in the memory block linked list of the heap, and initializing the mapping array; the size of each heap memory block is not fixed, and one mapping memory at least corresponds to one heap memory block.
Optionally, the array initialization module is specifically configured to: determining the memory size of each array element of the mapping array according to the system address bit width; according to a second formula: and calculating the memory size of the mapping array, namely the size of the heap memory/the size of the mapping memory, namely the size of the array elements.
Optionally, the array initialization module is specifically configured to: calculating a starting subscript of a mapping array corresponding to a head address of the current heap memory block and an ending subscript of the mapping array corresponding to a tail address according to a first formula; updating array elements between the starting subscript and the ending subscript of the mapping array by using the head address of the current heap memory block; and updating the current heap memory block, and returning to execute the operation of calculating the starting subscript of the mapping array corresponding to the head address and the ending subscript of the mapping array corresponding to the tail address of the current heap memory block according to the first formula until all heap memory blocks in the heap memory block linked list are mapped.
Optionally, the method further includes: the updating module is used for judging whether a new heap memory block is generated or not when the operation of allocating the memory or releasing the memory is detected; and if so, updating the mapping array according to the head address and the tail address of each new heap memory block.
Optionally, the method further includes: and the traversing module is used for traversing other heap memory blocks in the heap memory block linked list from the heap memory block head address according to the direction of the memory address becoming smaller after the memory block head address corresponding to the subscript value is obtained from the mapping array and if the target memory address does not belong to the memory address range corresponding to the heap memory block head address, so as to find out the target heap memory block matched with the target memory address.
The heap memory block search device provided by the embodiment of the invention can execute the heap memory block search method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
EXAMPLE III
Fig. 3 is a schematic structural diagram of an apparatus in a third embodiment of the present invention. FIG. 3 illustrates a block diagram of an exemplary device 12 suitable for use in implementing embodiments of the present invention, as applied to an embedded system. The device 12 shown in fig. 3 is only an example and should not bring any limitations to the functionality and scope of use of the embodiments of the present invention.
As shown in FIG. 3, device 12 is in the form of a general purpose computing device. The components of device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, micro-channel architecture (MAC) bus, enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Device 12 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)30 and/or cache memory 32. Device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 3, and commonly referred to as a "hard drive"). Although not shown in FIG. 3, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 42 generally carry out the functions and/or methodologies of the described embodiments of the invention.
Device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with device 12, and/or with any devices (e.g., network card, modem, etc.) that enable device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) via the network adapter 20. As shown, the network adapter 20 communicates with the other modules of the device 12 via the bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
The processing unit 16 executes programs stored in the system memory 28 to execute various functional applications and data processing, for example, to implement the heap memory block search method provided by the embodiment of the present invention.
Namely: the method for searching the heap memory block is applied to an embedded system and comprises the following steps:
acquiring a target memory address, and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
acquiring a heap memory block initial address corresponding to the subscript value from the mapping array;
and if the target memory address belongs to the memory address range corresponding to the head address of the heap memory block, determining the heap memory block corresponding to the head address of the heap memory block as a target heap memory block matched with the target memory address.
Example four
A fourth embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is used to execute a heap memory block search method when executed by a computer processor, and the method is applied to an embedded system, and includes:
acquiring a target memory address, and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
acquiring a heap memory block initial address corresponding to the subscript value from the mapping array;
and if the target memory address belongs to the memory address range corresponding to the head address of the heap memory block, determining the heap memory block corresponding to the head address of the heap memory block as a target heap memory block matched with the target memory address.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (9)

1. A heap memory block searching method is applied to an embedded system and comprises the following steps:
acquiring a target memory address, and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
acquiring a heap memory block head address corresponding to the subscript value from the mapping array;
if the target memory address belongs to the memory address range corresponding to the heap memory block head address, determining the heap memory block corresponding to the heap memory block head address as a target heap memory block matched with the target memory address;
before obtaining a target memory address and calculating a subscript value of a mapping array corresponding to the target memory address, the method further includes:
equally dividing the heap memories into mapping memories with fixed sizes, wherein the size of the mapping memories is larger than or equal to the size of the minimum heap memory block;
calculating the memory size of the mapping array according to the heap memory size and the mapping memory size;
distributing corresponding memories for the mapping arrays according to the memory sizes of the mapping arrays;
traversing each heap memory block in a memory block linked list of the heap, and initializing the mapping array;
the size of each heap memory block is not fixed, and one mapping memory at least corresponds to one heap memory block.
2. The method of claim 1, wherein calculating the index value of the mapping array corresponding to the target memory address comprises:
according to a first formula:
Figure FDA0003363124700000011
calculating subscript values of mapping arrays corresponding to the target memory addresses;
wherein the operation sign
Figure FDA0003363124700000012
Indicating a ceiling operation.
3. The method of claim 1, wherein calculating the memory size of the mapping array based on the heap memory size and the mapping memory size comprises:
determining the memory size of each array element of the mapping array according to the system address bit width;
according to a second formula: and calculating the memory size of the mapping array, namely the size of the heap memory/the size of the mapping memory, namely the size of the array elements.
4. The method according to claim 1, wherein traversing each heap memory block in a memory block linked list of a heap, and initializing the mapping array comprises:
calculating a starting subscript of a mapping array corresponding to a head address of the current heap memory block and an ending subscript of the mapping array corresponding to a tail address according to a first formula;
updating array elements between the starting subscript and the ending subscript of the mapping array by using the head address of the current heap memory block;
and updating the current heap memory block, and returning to execute the operation of calculating the starting subscript of the mapping array corresponding to the head address and the ending subscript of the mapping array corresponding to the tail address of the current heap memory block according to the first formula until all heap memory blocks in the heap memory block linked list are mapped.
5. The method of claim 1, further comprising:
when detecting the operation of allocating the memory or releasing the memory, judging whether a new memory heap block is generated;
and if so, updating the mapping array according to the head address and the tail address of each new heap memory block.
6. The method according to any one of claims 1 to 5, further comprising, after obtaining the memory block head address corresponding to the subscript value from the mapping array:
and if the target memory address does not belong to the memory address range corresponding to the heap memory block head address, traversing other heap memory blocks in the heap memory block linked list from the heap memory block head address according to the direction that the memory address becomes smaller so as to find the target heap memory block matched with the target memory address.
7. The utility model provides a heap memory piece seeking device which characterized in that is applied to embedded system, includes:
the calculation module is used for acquiring a target memory address and calculating a subscript value of a mapping array corresponding to the target memory address; each array element of the mapping array corresponds to a mapping memory with a fixed size, and the head address of the heap memory block comprising the tail address of the mapping memory corresponding to each array element is stored in each array element;
the obtaining module is used for obtaining the heap memory block initial address corresponding to the subscript value from the mapping array;
a determining module, configured to determine, if the target memory address belongs to the memory address range corresponding to the heap memory block head address, that the heap memory block corresponding to the heap memory block head address is a target heap memory block that is matched with the target memory address;
the array initialization module is used for equally dividing the heap memory into mapping memories with fixed sizes before acquiring a target memory address and calculating a subscript value of a mapping array corresponding to the target memory address, wherein the size of the mapping memory is larger than or equal to the size of a minimum heap memory block; calculating the memory size of the mapping array according to the heap memory size and the mapping memory size; distributing corresponding memories for the mapping arrays according to the memory sizes of the mapping arrays; traversing each heap memory block in the memory block linked list of the heap, and initializing the mapping array; the size of each heap memory block is not fixed, and one mapping memory at least corresponds to one heap memory block.
8. A computing device, for use in an embedded system, the computing device comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the heap memory chunk lookup method of any one of claims 1-6.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the heap memory block lookup method according to any one of claims 1 to 6.
CN201911341124.5A 2019-12-23 2019-12-23 Heap memory block searching method, device, equipment and storage medium Active CN111104347B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911341124.5A CN111104347B (en) 2019-12-23 2019-12-23 Heap memory block searching method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911341124.5A CN111104347B (en) 2019-12-23 2019-12-23 Heap memory block searching method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111104347A CN111104347A (en) 2020-05-05
CN111104347B true CN111104347B (en) 2022-03-25

Family

ID=70423383

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911341124.5A Active CN111104347B (en) 2019-12-23 2019-12-23 Heap memory block searching method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111104347B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112685333B (en) * 2020-12-28 2024-06-07 上海创功通讯技术有限公司 Heap memory management method and device
CN115827573B (en) * 2023-02-16 2023-06-02 麒麟软件有限公司 Linux-based key-value shape data storage and use method
CN117251120B (en) * 2023-11-17 2024-03-01 杭州乒乓智能技术有限公司 Accounting system optimization method, device, equipment and medium based on jvm out-of-heap memory

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103778061A (en) * 2014-01-17 2014-05-07 南京航空航天大学 Automatic detection and correction method for array out-of-bound errors
CN108563507A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of EMS memory management process, device, equipment and readable storage medium storing program for executing

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7162608B2 (en) * 2001-10-24 2007-01-09 Cray, Inc. Translation lookaside buffer-based memory system and method for use in a computer having a plurality of processor element
CN1287291C (en) * 2004-01-02 2006-11-29 中兴通讯股份有限公司 Method of internal storage releasing in embedded type real time operation system
US8468297B2 (en) * 2010-06-23 2013-06-18 International Business Machines Corporation Content addressable memory system
CN102831068B (en) * 2011-06-13 2016-04-06 阿里巴巴集团控股有限公司 A kind of disposal route of internal memory operation record and device
CN105677879B (en) * 2016-01-12 2019-10-18 诸葛晴凤 The data organization and access method of relationship memory database
CN107844372B (en) * 2017-10-17 2021-09-07 广东睿江云计算股份有限公司 Memory allocation method and system
CN108388517A (en) * 2018-03-14 2018-08-10 深圳怡化电脑股份有限公司 A kind of internal-memory detection method, device, equipment and storage medium
CN109508235B (en) * 2018-09-28 2020-12-15 深圳市紫光同创电子有限公司 Memory pool management method and device and computer readable storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103778061A (en) * 2014-01-17 2014-05-07 南京航空航天大学 Automatic detection and correction method for array out-of-bound errors
CN108563507A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of EMS memory management process, device, equipment and readable storage medium storing program for executing

Also Published As

Publication number Publication date
CN111104347A (en) 2020-05-05

Similar Documents

Publication Publication Date Title
CN111090628B (en) Data processing method and device, storage medium and electronic equipment
CN111104347B (en) Heap memory block searching method, device, equipment and storage medium
US9213623B2 (en) Memory allocation with identification of requesting loadable kernel module
US9342336B2 (en) Memory page de-duplication in a computer system that includes a plurality of virtual machines
US9836397B2 (en) Direct memory access of dynamically allocated memory
WO2017107414A1 (en) File operation method and device
CN108733309B (en) Storage management method, apparatus and computer readable medium
US9389997B2 (en) Heap management using dynamic memory allocation
CN112346647B (en) Data storage method, device, equipment and medium
US11099761B2 (en) Method, device and computer program product for expanding storage space
CN109284108B (en) Unmanned vehicle data storage method and device, electronic equipment and storage medium
US10747452B1 (en) Hybrid log-structured array and allocated storage device
CN109033456B (en) Condition query method and device, electronic equipment and storage medium
US9489309B2 (en) Method and system for dynamic cache partitioning using address remapping
US9891824B2 (en) Sub-block input/output (I/O) commands for storage device including byte stream buffer
CN114781322B (en) Memory state recovery method for MMU-free environment in CPU chip simulation acceleration
US10846023B2 (en) Storage device and storage area management method for reducing garbage collection processing
US9519592B2 (en) Stale pointer detection with overlapping versioned memory
CN109189332A (en) A kind of disk hanging method, device, server and storage medium
CN114385891A (en) Data searching method and device, electronic equipment and storage medium
CN111897484B (en) Data storage method and device, electronic equipment and storage medium
CN109491620B (en) Storage data rewriting method, device, server and storage medium
CN111897632B (en) Interrupt processing method and device, electronic equipment and storage medium
CN107977282B (en) Method and device for reading data page by SPI-Nand
CN113760781A (en) Data processing method and device, electronic equipment and storage medium

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