CN112000482A - Memory management method and device, electronic equipment and storage medium - Google Patents

Memory management method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN112000482A
CN112000482A CN202010866062.6A CN202010866062A CN112000482A CN 112000482 A CN112000482 A CN 112000482A CN 202010866062 A CN202010866062 A CN 202010866062A CN 112000482 A CN112000482 A CN 112000482A
Authority
CN
China
Prior art keywords
node
memory
pointer
preset
memory space
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
CN202010866062.6A
Other languages
Chinese (zh)
Other versions
CN112000482B (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 Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network 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 Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202010866062.6A priority Critical patent/CN112000482B/en
Publication of CN112000482A publication Critical patent/CN112000482A/en
Application granted granted Critical
Publication of CN112000482B publication Critical patent/CN112000482B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a memory management method and device, electronic equipment and a storage medium, and relates to the technical field of data storage. The scheme of the embodiment of the application comprises the following steps: when a first node included in the red-black tree is deleted, determining a first memory space occupied by the first node in a preset memory pool, wherein the preset memory pool is used for storing the nodes included in the red-black tree, and the first node is any node included in the red-black tree; and then mounting the first memory space to a preset available space table. The waste of memory resources can be avoided.

Description

Memory management method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of data storage technologies, and in particular, to a method and an apparatus for memory management, an electronic device, and a storage medium.
Background
At present, in order to ensure the efficiency of querying and updating data nodes in a memory, a red and black tree mode may be adopted to cache the data nodes in the memory. When data insertion exists, a memory can be applied, and a data node is established in the applied memory; when the data is deleted, the memory occupied by the data node can be released. The insertion and deletion of data causes the memory to be frequently applied and released.
After the database runs for a long time, the memory is frequently applied and released, so that a large number of memory fragments exist in the memory, and the memory fragments cannot be used due to the fact that the memory fragments are small and discontinuous in the memory, and waste of memory resources is caused.
Disclosure of Invention
Embodiments of the present invention provide a method and an apparatus for memory management, an electronic device, and a storage medium, so as to avoid waste of memory resources. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present application provides a method for memory management, including:
when a first node included in a red-black tree is deleted, determining a first memory space occupied by the first node in a preset memory pool, wherein the preset memory pool is used for storing the nodes included in the red-black tree, and the first node is any node included in the red-black tree;
and mounting the first memory space to a preset available space table.
In one possible implementation, the preset available space table is a double linked list; the mounting the first memory space to a preset available space table includes:
acquiring a left child node pointer and a right child node pointer of the first node, wherein the left child node pointer points to the starting address of the left child node of the first node in the preset memory pool, and the right child node pointer points to the starting address of the right child node of the first node in the preset memory pool;
modifying the pointing direction of the left child node pointer to be: setting the pointer of the right child node as null according to the initial address of the memory space in the preset available space table in the preset memory pool, which is newly mounted;
modifying the pointing direction of a back pointer which is newly mounted to the memory space in the preset available space table into the initial address of the first memory space in the preset memory pool;
and mounting the first memory space to the preset available space table, taking the left child node pointer as a front pointer of the first memory space, and taking the right child node pointer as a back pointer of the first memory space.
In one possible implementation, the method further includes:
when a second node is inserted into the red and black tree, allocating a memory space for the second node from the preset memory pool;
if the preset memory pool has no available memory space, allocating a second memory space for the second node from the preset available space table;
storing the second node in the second memory space;
and unloading the second memory space from the preset available space table.
In a possible implementation manner, the storing the second node in the second memory space includes:
acquiring a front pointer and a back pointer of the second memory space;
modifying the pointing direction of the front pointer of the second memory space to be: and the starting address of the left child node of the second node in the preset memory pool modifies the direction of the back pointer of the second memory space into: the starting address of the right child node of the second node in the preset memory pool;
and storing the data of the second node in the second memory space, taking a front pointer of the second memory space as a left child node pointer of the second node, and taking a back pointer of the second memory space as a right child node pointer of the second node.
In a second aspect, an embodiment of the present application provides an apparatus for memory management, including:
the determining module is configured to determine, when a first node included in a red-black tree is deleted, a first memory space occupied by the first node in a preset memory pool, where the preset memory pool is used for storing the nodes included in the red-black tree, and the first node is any node included in the red-black tree;
and the mounting module is used for mounting the first memory space to a preset available space table.
In a possible implementation manner, the structure of the preset available space table is a double linked list; the mounting module is specifically used for:
acquiring a left child node pointer and a right child node pointer which are included by the first node, wherein the left child node pointer points to the initial address of the left child node of the first node in the preset memory pool, and the right child node pointer points to the initial address of the right child node of the first node in the preset memory pool;
modifying the pointing direction of the left child node pointer to be: setting the pointer of the right child node as null according to the initial address of the memory space in the preset available space table in the preset memory pool, which is newly mounted;
modifying the pointing direction of a back pointer which is newly mounted to the memory space in the preset available space table into the initial address of the first memory space in the preset memory pool;
and mounting the first memory space to the preset available space table, taking the left child node pointer as a front pointer of the first memory space, and taking the right child node pointer as a back pointer of the first memory space.
In one possible implementation, the apparatus further includes:
the allocation module is used for allocating a memory space for a second node from the preset memory pool when the second node is inserted into the red-black tree; and the second node is used for allocating a second memory space to the second node from the preset available space table if the preset memory pool has no available memory space;
a storage module, configured to store the second node in the second memory space;
and the deleting module is used for unloading the second memory space from the preset available space table.
In a possible implementation manner, the storage module is specifically configured to:
acquiring a front pointer and a back pointer of the second memory space;
modifying the pointing direction of the front pointer of the second memory space to be: and the starting address of the left child node of the second node in the preset memory pool modifies the direction of the back pointer of the second memory space into: the starting address of the right child node of the second node in the preset memory pool;
and storing the data of the second node in the second memory space, taking a front pointer of the second memory space as a left child node pointer of the second node, and taking a back pointer of the second memory space as a right child node pointer of the second node.
In a third aspect, an embodiment of the present invention further provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor and the communication interface complete communication between the memory and the processor through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing any one of the above method steps of memory management when executing the program stored in the memory.
In a fourth aspect, this application further provides a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the method for memory management in the first aspect is implemented.
In a fifth aspect, an embodiment of the present application further provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the method for memory management described in the first aspect.
The embodiment of the invention has the following beneficial effects:
by adopting the technical scheme, when the first node included in the red and black tree is deleted, the first memory space occupied by the first node is not released to the preset memory pool, but the first memory space is mounted to the preset available space table, so that memory fragments generated in the preset memory pool are avoided. Because the memory space occupied by each node in the red and black tree is the same, the memory space in the preset available space table can be used by other nodes subsequently inserted in the red and black tree, and the waste of memory resources is avoided.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a schematic diagram of an exemplary red-black tree provided in an embodiment of the present application;
fig. 2 is a flowchart of a method for memory management according to an embodiment of the present disclosure;
fig. 3 is an exemplary schematic diagram of a default memory pool according to an embodiment of the present disclosure;
fig. 4 is a flowchart of a method for mounting a memory space to a preset available space table in a memory management method according to an embodiment of the present disclosure;
FIG. 5 is an exemplary diagram of a preset available space table according to an embodiment of the present application;
fig. 6 is a flowchart of a method for allocating memory space for nodes in a red-black tree according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of a memory management apparatus according to an embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
For convenience of understanding, the related terms referred to in the embodiments of the present application are explained first.
Red and black trees: the self-balancing binary search tree is a data structure used in computer science, and is typically used for association arrays.
As shown in fig. 1, fig. 1 is a schematic structural diagram of a red-black tree according to an embodiment of the present application. The color of the root node, node 3, node 4, node 5, and node 6 in fig. 1 is black, and the color of the node 1 and node 2 is red.
Each node of the red-black tree includes a left child node pointer and a right child node pointer of the node, the large circle in fig. 1 represents the node, and the small circle represents the left child node pointer (denoted as L in fig. 1) and the right child node pointer (denoted as R in fig. 1) of the node.
Taking the root node in fig. 1 as an example, the left child node of the root node is node 1, and the right child node of the root node is node 2. The left child pointer of the root node points to the start address of node 1 and the right child pointer of the root node points to the start address of node 2.
In order to reduce waste of memory resources, an embodiment of the present application provides a method for memory management, where the method includes: when a first node included in the red and black tree is deleted, determining a first memory space occupied by the first node in a preset memory pool, and mounting the first memory space to a preset available space table. The preset memory pool is used for storing nodes included in the red-black tree, and the first node is any node included in the red-black tree.
By adopting the method, the first memory space occupied by the first node can be mounted to the preset available space table, and the memory space in the preset available space table can also be used by other nodes subsequently inserted in the red-black tree, so that the waste of memory resources is avoided.
The memory management method provided by the embodiments of the present application is described in detail below with reference to specific embodiments.
As shown in fig. 2, an embodiment of the present application provides a method for memory management, where the method is applied to an electronic device, where the electronic device may be a server or other device for managing a database, and the method includes:
s201, when a first node included in the red and black tree is deleted, determining a first memory space occupied by the first node in a preset memory pool.
The preset memory pool is used for storing nodes included in the red-black tree, and the first node is any node included in the red-black tree.
When the database is started, a preset memory pool can be generated, and an operating system of the electronic device is applied for a memory to serve as the memory of the preset memory pool. As shown in fig. 3, fig. 3 is an exemplary diagram of a preset memory pool, where the preset memory pool includes a plurality of memory spaces, and each memory space of the preset memory pool can be used for storing one node in a red-black tree. Fig. 3 is only an example, and the number of memory spaces in the preset memory pool in an actual implementation is not limited thereto. The memory included in the preset memory pool is an exclusive memory of the red-black tree. Alternatively, the address of each memory space in the preset memory pool may be represented by a relative address.
S202, mounting the first memory space to a preset available space table.
By adopting the method, when the first node included in the red and black tree is deleted, the first memory space occupied by the first node is not released to the preset memory pool, but the first memory space is mounted to the preset available space table, so that memory fragments are prevented from being generated in the preset memory pool. Because the memory space occupied by each node in the red and black tree is the same, the memory space in the preset available space table can be used by other nodes subsequently inserted in the red and black tree, and the waste of memory resources is avoided.
In an embodiment of the present application, the structure of the preset available space table is a doubly linked list. As shown in fig. 4, in the step S202, the mounting the first memory space to the preset available space table specifically includes the following steps:
s401, acquiring a left child node pointer and a right child node pointer included by the first node.
The left child node pointer points to the starting address of the left child node of the first node in the preset memory pool, and the right child node pointer points to the starting address of the right child node of the first node in the preset memory pool.
Referring to fig. 1, if the first node is node 1, the left child node of the first node is node 3, and the right child node of the first node is node 4. A left child node pointer of the node 1 points to the initial address of the node 3 in the preset memory pool; the right subsection pointer of node 1 points to the starting address of node 4 in the preset memory pool.
S402, modifying the pointing direction of the left child node pointer into: and (4) the latest mounting is carried out to the initial address of the memory space in the preset available space table in the preset memory pool, and the pointing direction of the right child node pointer is set to be null.
S403, the pointing direction of the back pointer which is newly mounted to the memory space in the preset available space table is modified into the initial address of the first memory space in the preset memory pool.
S404, the first memory space is mounted to a preset available space table, the left child node pointer is used as a front pointer of the first memory space, and the right child node pointer is used as a back pointer of the first memory space.
It should be noted that the embodiment of the present application does not limit the execution sequence of S402, S403, and S404, and S402 to S404 are sequentially executed in fig. 4 as an example.
Referring to fig. 5, the above process is described, and as shown in fig. 5, it is assumed that before the first memory space is mounted to the preset available space table, the preset available space table includes memory spaces 1 to 3, and since the memory space 3 is the latest memory space mounted to the preset available space table, the pointer of the back pointer of the memory space 3 is null.
If the first memory space is mounted to the preset available space table, the back pointer of the memory space 3 points to the initial address of the first memory space in the preset address pool, so that the pointing of the back pointer of the memory space 3 is updated as follows: the first memory space is the starting address in the preset address pool.
Accordingly, the front pointer of the first memory space points to the starting address of the memory space 3 in the preset address pool. The first memory space is now the last memory space in the default available space table, so the pointer of the back pointer of the first memory space is null.
As an example, assuming that a start address of a first block of memory space in a predetermined memory pool is 0 and a size of each memory space is 300 bytes, assuming that the first memory space is a third block of memory space in the predetermined memory pool, a start address of the first memory space in the predetermined memory pool is 600.
It can be understood that the memory space first released by the red-black tree is first mounted into the preset available space table, that is, each time a memory space is released in the red-black tree, the memory space is mounted into the preset available space table.
The memory space 1, the memory space 2, and the memory space 3 shown in fig. 5 may be discontinuous memory spaces in the preset memory pool, for example, the 7 th block memory space in the preset memory pool is released by the blacktree in sequence, the 7 th block memory space in the preset memory pool may be the memory space 1 in fig. 5, the 1 st block memory space in the preset memory pool may be the memory space 2 in fig. 5, and the 5 th block memory space in the preset memory pool may be the memory space 3 in fig. 5.
In this embodiment of the present application, the data structure of the node of the red-black tree includes a left child node pointer and a right child node pointer, and when the first memory space of the first node is mounted in the preset available space table, the data structure of the first node may not be changed, the left child node pointer of the first node is used as a front pointer of the first memory space, and the right child node pointer of the first node is used as a back pointer of the first memory space. Referring to fig. 5, "L" in fig. 5 is a left child node pointer in a node of the red-black tree, which is used as a front pointer in a preset available space table; "R" in fig. 5 is a right child node pointer in a node of the red-black tree, and is used as a back pointer in the preset available space table.
By adopting the method, when the memory space corresponding to the node in the red and black tree is mounted in the preset available space table, the left child node pointer and the right child node pointer of the node can be directly used, and the front pointer and the rear pointer are not additionally generated for the memory space, so that the memory space can be saved.
In addition, in the related art, when there is a new node in the red-black tree, a memory space needs to be applied to the operating system, and the data type used by the 64-bit operating system is a long and integer type (long type), that is, the lengths of the left child node pointer and the right child node pointer of the node of the red-black tree are both 8 bytes.
In this embodiment of the present application, all nodes in the red and black tree use a memory space in a preset memory pool for storage, and the preset memory pool is only used for storing the nodes in the red and black tree. Furthermore, the data type used in this embodiment may be integer (int type), and the left child node pointer and the right child node pointer of the node included in the red-black tree are both represented by four bytes of characters. Correspondingly, the pre-set available space table includes a front pointer and a back pointer of the memory space, which are both represented by four bytes.
It can be seen that, by adopting the embodiment of the application, the memory space of at least 8 bytes can be saved for each node in the red and black tree.
In another embodiment of the present application, a method for allocating memory space for nodes in a red-black tree is provided, as shown in fig. 6, the method includes:
s601, when a second node is inserted into the red and black tree, allocating a memory space for the second node from a preset memory pool.
And the second node is the node inserted into the red and black tree.
S602, if there is no available memory space in the preset memory pool, allocating a second memory space for the second node from the preset available space table.
It can be understood that, when a node in the red-black tree is deleted, the released memory space is not used as a free memory space in the preset memory pool, but is mounted in the preset available space table to be managed in a centralized manner, so that when there is no available memory space in the preset memory pool, a second memory space can be allocated to the second node from the preset available space table.
And S603, storing the second node in the second memory space.
Since the second memory space has a front pointer and a back pointer that are originally left child node pointers and right child node pointers of the released node, when the second memory space is reused by nodes in the red-black tree, the front pointer and the back pointer can be reused as the left child node pointer and the right child node pointer. Based on this, the step can be specifically realized as follows:
acquiring a front pointer and a back pointer of the second memory space, and modifying the direction of the front pointer of the second memory space into: and the left child node of the second node modifies the pointing direction of the back pointer of the second memory space into the initial address in the preset memory pool: and the starting address of the right child node of the second node in the preset memory pool. And storing the data of the second node in the second memory space, taking the front pointer of the second memory space as the left child node pointer of the second node, and taking the back pointer of the second memory space as the right child node pointer of the second node.
S604, unloading the second memory space from the preset available space table.
Since the second memory space is already occupied, the second memory space can be unloaded from the preset available space table, and the pointing direction of the pointer of the memory space adjacent to the second memory space in the preset available space table can be adjusted. For example, assuming that the second memory space is the last memory space in the preset available space table, after the second memory space is occupied, the pointer of the back pointer of the previous memory space in the second memory space is set to be null.
By adopting the method, the memory size occupied by each node in the same red and black tree is the same, so that the memory space required by the second node is the same as the memory space in each block in the preset available space table, the second memory space in the preset available space table is distributed to the second node, the memory fragments can be avoided, and the second memory space can be fully utilized.
Based on the same technical concept, an embodiment of the present application further provides a device for memory management, as shown in fig. 7, the device includes:
a determining module 701, configured to determine, when a first node included in the red-black tree is deleted, a first memory space occupied by the first node in a preset memory pool, where the preset memory pool is used to store the nodes included in the red-black tree, and the first node is any node included in the red-black tree;
a mounting module 702 is configured to mount the first memory space to a preset available space table.
In one embodiment, the structure of the available space table is preset as a double-linked list; the mounting module 702 is specifically configured to:
acquiring a left child node pointer and a right child node pointer which are included by a first node, wherein the left child node pointer points to the initial address of the left child node of the first node in a preset memory pool, and the right child node pointer points to the initial address of the right child node of the first node in the preset memory pool;
the pointing direction of the pointer of the left child node is modified to be: the latest mounting is carried out to the initial address of the memory space in the preset available space table in the preset memory pool, and the pointing direction of the right child node pointer is set to be null;
modifying the pointing direction of a back pointer which is newly mounted to a memory space in a preset available space table into the initial address of the first memory space in a preset memory pool;
and mounting the first memory space to a preset available space table, taking the left child node pointer as a front pointer of the first memory space, and taking the right child node pointer as a back pointer of the first memory space.
In one embodiment, the apparatus further comprises:
the allocation module is used for allocating memory space for the second node from the preset memory pool when the second node is inserted into the red-black tree; and the second node is used for allocating a second memory space to the second node from the preset available space table if the preset memory pool has no available memory space;
the storage module is used for storing the second node in the second memory space;
and the deleting module is used for unloading the second memory space from the preset available space table.
In one embodiment, the storage module is specifically configured to:
acquiring a front pointer and a back pointer of a second memory space;
modifying the pointing of the front pointer of the second memory space to: and the left child node of the second node modifies the pointing direction of the back pointer of the second memory space into the initial address in the preset memory pool: the starting address of the right child node of the second node in the preset memory pool;
and storing the data of the second node in the second memory space, taking a front pointer of the second memory space as a left child node pointer of the second node, and taking a back pointer of the second memory space as a right child node pointer of the second node.
By adopting the device, when the first node included in the red and black tree is deleted, the first memory space occupied by the first node is not released to the preset memory pool, but the first memory space is mounted to the preset available space table, so that memory fragments generated in the preset memory pool are avoided. Because the memory space occupied by each node in the red and black tree is the same, the memory space in the preset available space table can be used by other nodes subsequently inserted in the red and black tree, and the waste of memory resources is avoided.
Based on the same technical concept, the embodiment of the present invention further provides an electronic device, as shown in fig. 8, including a processor 801, a communication interface 802, a memory 803 and a communication bus 804, where the processor 801, the communication interface 802 and the memory 803 complete communication with each other through the communication bus 804,
a memory 803 for storing a computer program;
the processor 801 is configured to implement the steps of any memory management method in the foregoing method embodiments when executing the program stored in the storage 803.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
In another embodiment of the present invention, a computer-readable storage medium is further provided, in which a computer program is stored, and the computer program, when executed by a processor, implements the steps of any of the above memory management methods.
In another embodiment, the present invention further provides a computer program product containing instructions, which when run on a computer, causes the computer to execute any of the memory management methods in the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, the storage medium, and the computer program product embodiment, since they are substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to part of the description of the method embodiment.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (10)

1. A method for memory management, comprising:
when a first node included in a red-black tree is deleted, determining a first memory space occupied by the first node in a preset memory pool, wherein the preset memory pool is used for storing the nodes included in the red-black tree, and the first node is any node included in the red-black tree;
and mounting the first memory space to a preset available space table.
2. The method of claim 1, wherein the pre-set available space table is a doubly linked list; the mounting the first memory space to a preset available space table includes:
acquiring a left child node pointer and a right child node pointer of the first node, wherein the left child node pointer points to the starting address of the left child node of the first node in the preset memory pool, and the right child node pointer points to the starting address of the right child node of the first node in the preset memory pool;
modifying the pointing direction of the left child node pointer to be: setting the pointer of the right child node as null according to the initial address of the memory space in the preset available space table in the preset memory pool, which is newly mounted;
modifying the pointing direction of a back pointer which is newly mounted to the memory space in the preset available space table into the initial address of the first memory space in the preset memory pool;
and mounting the first memory space to the preset available space table, taking the left child node pointer as a front pointer of the first memory space, and taking the right child node pointer as a back pointer of the first memory space.
3. The method according to claim 1 or 2, characterized in that the method further comprises:
when a second node is inserted into the red and black tree, allocating a memory space for the second node from the preset memory pool;
if the preset memory pool has no available memory space, allocating a second memory space for the second node from the preset available space table;
storing the second node in the second memory space;
and unloading the second memory space from the preset available space table.
4. The method of claim 3, wherein storing the second node in the second memory space comprises:
acquiring a front pointer and a back pointer of the second memory space;
modifying the pointing direction of the front pointer of the second memory space to be: and the starting address of the left child node of the second node in the preset memory pool modifies the direction of the back pointer of the second memory space into: the starting address of the right child node of the second node in the preset memory pool;
and storing the data of the second node in the second memory space, taking a front pointer of the second memory space as a left child node pointer of the second node, and taking a back pointer of the second memory space as a right child node pointer of the second node.
5. An apparatus for memory management, comprising:
the determining module is configured to determine, when a first node included in a red-black tree is deleted, a first memory space occupied by the first node in a preset memory pool, where the preset memory pool is used for storing the nodes included in the red-black tree, and the first node is any node included in the red-black tree;
and the mounting module is used for mounting the first memory space to a preset available space table.
6. The apparatus of claim 5, wherein the structure of the preset available space table is a doubly linked list; the mounting module is specifically used for:
acquiring a left child node pointer and a right child node pointer which are included by the first node, wherein the left child node pointer points to the initial address of the left child node of the first node in the preset memory pool, and the right child node pointer points to the initial address of the right child node of the first node in the preset memory pool;
modifying the pointing direction of the left child node pointer to be: setting the pointer of the right child node as null according to the initial address of the memory space in the preset available space table in the preset memory pool, which is newly mounted;
modifying the pointing direction of a back pointer which is newly mounted to the memory space in the preset available space table into the initial address of the first memory space in the preset memory pool;
and mounting the first memory space to the preset available space table, taking the left child node pointer as a front pointer of the first memory space, and taking the right child node pointer as a back pointer of the first memory space.
7. The apparatus of claim 5 or 6, further comprising:
the allocation module is used for allocating a memory space for a second node from the preset memory pool when the second node is inserted into the red-black tree; and the second node is used for allocating a second memory space to the second node from the preset available space table if the preset memory pool has no available memory space;
a storage module, configured to store the second node in the second memory space;
and the deleting module is used for unloading the second memory space from the preset available space table.
8. The apparatus of claim 7, wherein the storage module is specifically configured to:
acquiring a front pointer and a back pointer of the second memory space;
modifying the pointing direction of the front pointer of the second memory space to be: and the starting address of the left child node of the second node in the preset memory pool modifies the direction of the back pointer of the second memory space into: the starting address of the right child node of the second node in the preset memory pool;
and storing the data of the second node in the second memory space, taking a front pointer of the second memory space as a left child node pointer of the second node, and taking a back pointer of the second memory space as a right child node pointer of the second node.
9. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1 to 4 when executing a program stored in the memory.
10. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 4.
CN202010866062.6A 2020-08-25 2020-08-25 Memory management method and device, electronic equipment and storage medium Active CN112000482B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010866062.6A CN112000482B (en) 2020-08-25 2020-08-25 Memory management method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010866062.6A CN112000482B (en) 2020-08-25 2020-08-25 Memory management method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112000482A true CN112000482A (en) 2020-11-27
CN112000482B CN112000482B (en) 2024-03-05

Family

ID=73470755

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010866062.6A Active CN112000482B (en) 2020-08-25 2020-08-25 Memory management method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112000482B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115016918A (en) * 2022-03-31 2022-09-06 中国科学院计算技术研究所 Data processing method for computing equipment of data flow architecture

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6411957B1 (en) * 1999-06-30 2002-06-25 Arm Limited System and method of organizing nodes within a tree structure
US20100246446A1 (en) * 2009-03-30 2010-09-30 Wenhua Du Tree-based node insertion method and memory device
DE102009036095A1 (en) * 2009-08-04 2011-02-10 Giesecke & Devrient Gmbh Method for managing storage resources in a portable volume
WO2014195141A1 (en) * 2013-06-05 2014-12-11 Commissariat A L'energie Atomique Et Aux Energies Alternatives Material accelerator for handling red and black trees
WO2016054899A1 (en) * 2014-10-10 2016-04-14 中兴通讯股份有限公司 Flash file data recovery method and apparatus, and computer storage medium
CN109144712A (en) * 2017-06-19 2019-01-04 北京信威通信技术股份有限公司 Memory pool building, memory allocation method and device
CN110928882A (en) * 2019-11-27 2020-03-27 上海金仕达软件科技有限公司 Memory database indexing method and system based on improved red-black tree
CN111026762A (en) * 2019-12-12 2020-04-17 北京金山云网络技术有限公司 Red and black tree index generation method and device, electronic equipment and storage medium
CN111190861A (en) * 2019-12-27 2020-05-22 中移(杭州)信息技术有限公司 Hot file management method, server and computer readable storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6411957B1 (en) * 1999-06-30 2002-06-25 Arm Limited System and method of organizing nodes within a tree structure
US20100246446A1 (en) * 2009-03-30 2010-09-30 Wenhua Du Tree-based node insertion method and memory device
DE102009036095A1 (en) * 2009-08-04 2011-02-10 Giesecke & Devrient Gmbh Method for managing storage resources in a portable volume
WO2014195141A1 (en) * 2013-06-05 2014-12-11 Commissariat A L'energie Atomique Et Aux Energies Alternatives Material accelerator for handling red and black trees
WO2016054899A1 (en) * 2014-10-10 2016-04-14 中兴通讯股份有限公司 Flash file data recovery method and apparatus, and computer storage medium
CN109144712A (en) * 2017-06-19 2019-01-04 北京信威通信技术股份有限公司 Memory pool building, memory allocation method and device
CN110928882A (en) * 2019-11-27 2020-03-27 上海金仕达软件科技有限公司 Memory database indexing method and system based on improved red-black tree
CN111026762A (en) * 2019-12-12 2020-04-17 北京金山云网络技术有限公司 Red and black tree index generation method and device, electronic equipment and storage medium
CN111190861A (en) * 2019-12-27 2020-05-22 中移(杭州)信息技术有限公司 Hot file management method, server and computer readable storage medium

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
刘勇;: "红黑树在Linux虚拟内存区域管理中的应用", 科技信息, no. 23, 15 August 2013 (2013-08-15) *
葛瑶;李晓风;孔德光;: "基于红黑树的堆内存泄漏动态检测技术", 计算机工程, no. 16, 20 August 2008 (2008-08-20) *
陈毅辉;龙昭华;: "红黑树在RFID标签文件***中的研究与应用", 计算机工程与设计, no. 10, 16 October 2016 (2016-10-16) *
马博韬;孙鹏;朱小勇;: "红黑树算法研究综述", 网络新媒体技术, no. 04, 15 July 2018 (2018-07-15) *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115016918A (en) * 2022-03-31 2022-09-06 中国科学院计算技术研究所 Data processing method for computing equipment of data flow architecture
CN115016918B (en) * 2022-03-31 2024-06-11 中国科学院计算技术研究所 Data processing method for computing device of data flow architecture

Also Published As

Publication number Publication date
CN112000482B (en) 2024-03-05

Similar Documents

Publication Publication Date Title
CN108897628B (en) Method and device for realizing distributed lock and electronic equipment
WO2020211236A1 (en) Read-write conflict resolution method and apparatus employing b+ tree and storage medium
CN109213604B (en) Data source management method and device
CN108614976A (en) Authority configuring method, device and storage medium
CN111694638A (en) Rule package loading method, rule package executing method and terminal equipment
US9389997B2 (en) Heap management using dynamic memory allocation
US10101988B2 (en) Dynamic firmware updating
CN112860953A (en) Data importing method, device, equipment and storage medium of graph database
US11093389B2 (en) Method, apparatus, and computer program product for managing storage system
CN112068874A (en) Software project continuous integration method and device, terminal equipment and storage medium
CN114817146A (en) Method and device for processing data
CN112650692A (en) Heap memory allocation method, device and storage medium
CN111125240B (en) Distributed transaction realization method and device, electronic equipment and storage medium
CN112000482B (en) Memory management method and device, electronic equipment and storage medium
CN111159160A (en) Version rollback method and device, electronic equipment and storage medium
CN110162395B (en) Memory allocation method and device
EP3964996A1 (en) Database access method and device
CN113132241B (en) ACL template dynamic configuration method and device
CN112612530B (en) Class query method and device
WO2019071892A1 (en) Method for transmitting masking rules for sensitive information, application server, and computer readable storage medium
CN113986921A (en) Blacklist query method, system, electronic equipment and storage medium
CN113760237A (en) Compiling address updating method and device, terminal equipment and readable storage medium
CN113110846A (en) Method and device for acquiring environment variable
CN113254464B (en) Data loading method and device
US20230195901A1 (en) Model-based upgrade recommendations using software dependencies

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