Memory management method and device, equipment and storage medium
By adopting a ring memory pool management method in the monitoring device, the problem that monitoring device is prone to memory fragmentation and leakage when storing and releasing picture data is solved, and more efficient memory resource utilization and storage performance are achieved.
Patent Information
- Application Number
- CN202411731680.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-18
AI Technical Summary
Monitoring devices are prone to memory fragmentation and memory leakage when storing and releasing picture data, resulting in insufficient utilization of memory resources and affecting the storage performance of the device.
The ring memory pool management method is adopted to store monitoring data by finding free continuous memory blocks, and the storage location of data is determined based on the pre-created memory blocks and memory index information to avoid frequent application and freeing of memory.
It effectively avoids memory fragmentation and leakage, improves the utilization rate of memory resources, and reduces the impact on the memory storage performance of monitoring devices.
Smart Images

Figure CN119645890A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a memory management method, apparatus, device and storage medium. Background Art
[0002] As monitoring equipment is increasingly used, in many application fields, in order to ensure the safety of personnel and property, monitoring equipment can be used to identify abnormalities in the monitoring area and monitor and alarm for abnormal situations. In order to increase credibility and facilitate traceability, monitoring equipment will report the pictures captured at the abnormal moment when reporting the alarm event. The pictures captured at the abnormal moment need to be temporarily stored in the memory of the monitoring device.
[0003] In the related art, the system interface is frequently called to apply for system memory to store pictures captured at abnormal moments. Once these pictures are processed, the occupied memory space will be released. Due to different monitoring scenarios, the size of each picture is different. Frequent application and release of memory space of different sizes can easily cause memory fragmentation or memory leaks, which not only makes the memory space unable to be fully utilized, but also easily leads to a decrease in the memory storage performance or crash of the monitoring device. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a memory management method, apparatus, device and storage medium to solve the problem that memory fragmentation and memory leakage are prone to occur during the use of memory by monitoring data, resulting in insufficient utilization of memory resources.
[0005] To solve the above technical problems, the embodiments of the present application are implemented as follows: On the one hand, an embodiment of the present application provides a memory management method, including: In response to a memory usage request for monitoring data, searching a plurality of consecutive target memory blocks in an idle state from a ring memory pool; the ring memory pool includes n memory blocks, a first memory block in the ring memory pool is adjacent to an nth memory block; n is an integer greater than or equal to 3; Determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information; the target memory index information includes: the number of the target memory blocks and the starting position of the target memory block in the ring memory pool; Determining, according to the target memory index information, a starting storage position of the monitoring data in the plurality of continuous target memory blocks; The monitoring data is stored according to the initial storage location.
[0006] On the other hand, an embodiment of the present application provides a memory management device, including: A search module, configured to search for a plurality of consecutive target memory blocks in an idle state from a circular memory pool in response to a memory usage request for monitoring data; the circular memory pool includes n memory blocks, a first memory block in the circular memory pool is adjacent to an nth memory block; and n is an integer greater than or equal to 3; A first determination module is used to determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information; the target memory index information includes: the number of the target memory blocks and the starting position of the target memory block in the ring memory pool; A second determination module, configured to determine, according to the target memory index information, a starting storage position of the monitoring data in the plurality of continuous target memory blocks; A storage module is used to store the monitoring data according to the starting storage position.
[0007] On the other hand, an embodiment of the present application provides a memory management system, including a monitoring device, a memory management module and a ring memory pool connected in sequence; wherein: The monitoring device is used to send a memory usage request for monitoring data to the memory management module in response to a monitoring event; The memory management module is used to search for multiple continuous target memory blocks in an idle state from the annular memory pool in response to the memory use request; the annular memory pool includes n memory blocks, and the first memory block in the annular memory pool is adjacent to the nth memory block; n is an integer greater than or equal to 3; according to the multiple continuous target memory blocks, and the correspondence between the pre-created memory blocks and the memory index information, determine the target memory index information corresponding to the monitoring data; the target memory index information includes: the number of the target memory blocks and the starting position of the target memory block in the annular memory pool; according to the target memory index information, determine the starting storage position of the monitoring data in the multiple continuous target memory blocks; according to the starting storage position, perform storage processing on the monitoring data; The annular memory pool is used to store the monitoring data.
[0008] On the other hand, an embodiment of the present application provides a memory management device, including a processor; and a memory arranged to store computer-executable instructions, wherein the computer-executable instructions are configured to be executed by the processor, and the computer-executable instructions are executed by the processor to implement the above-mentioned memory management method.
[0009] On the other hand, an embodiment of the present application provides a storage medium for storing computer-executable instructions, which implement the above-mentioned memory management method when executed by a processor.
[0010] On the other hand, an embodiment of the present application provides a computer program product, including a computer program, which implements the above-mentioned memory management method when executed by a processor.
[0011] Adopting the technical solution of the embodiment of the present application, in response to a memory usage request for monitoring data, multiple continuous target memory blocks in an idle state are searched from a circular memory pool, the circular memory pool includes n memory blocks, and the first memory block in the circular memory pool is adjacent to the nth memory block, so as to determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information. Furthermore, according to the target memory index information, the starting storage position of the monitoring data in the multiple continuous target memory blocks is determined, and according to the starting storage position, the monitoring data is stored. Compared with the scheme of using the system interface to apply for and release data in the related art, in this technical scheme, on the one hand, the circular memory pool is used to store the monitoring data, which avoids the memory fragmentation generated during the storage and release of the monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. Moreover, by storing monitoring data in a plurality of continuous memory blocks in an idle state in a circular memory pool, not only the complexity of matching memory blocks for monitoring data is reduced, but also, compared with a memory pool with a unidirectional structure, if there are continuous memory blocks near the end (i.e., the nth memory block) and continuous memory blocks at the starting position (i.e., the first memory block) in the circular memory pool, which can form the above-mentioned plurality of continuous target memory blocks, the monitoring data can be stored in the circular memory pool, thereby avoiding the situation that the monitoring data cannot be stored due to the discontinuity of the idle memory blocks, wasting memory resources, and improving the utilization rate of memory resources. On the other hand, the memory index information corresponding to the monitoring data can be determined, so as to determine the starting storage position of the monitoring data according to the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when performing memory management (such as releasing memory) on the circular memory pool, the situation of the memory blocks occupied by a monitoring data can be quickly and accurately determined according to the memory index information, which is conducive to ensuring that the memory management steps are executed in a timely and accurate manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0013] Figure 1 is a schematic block diagram of a memory management system according to an embodiment of the present application; Figure 2 is a schematic block diagram of a memory management system according to another embodiment of the present application; Figure 3 is a schematic flow chart of a memory management method according to an embodiment of the present application; Figure 4 is a schematic block diagram of a ring memory pool according to an embodiment of the present application; Figure 5 is a schematic flow chart of a memory application process according to an embodiment of the present application; Figure 6 is a schematic flow chart of a memory release process according to an embodiment of the present application; Figure 7 is a schematic block diagram of a memory management device according to an embodiment of the present application; Figure 8 It is a structural diagram of a memory management device according to an embodiment of the present application. DETAILED DESCRIPTION
[0014] The embodiments of the present application provide a memory management method, apparatus, device and storage medium to solve the problem that memory fragmentation and memory leakage are prone to occur during the use of memory by monitoring data, resulting in insufficient utilization of memory resources.
[0015] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0016] Figure 1 is a schematic block diagram of a memory management system according to an embodiment of the present application, such as Figure 1 As shown, the memory management system may include a monitoring device 110, a memory management module 120 and a ring memory pool 130 connected in sequence.
[0017] In this embodiment, the monitoring device 110 is used to send a memory usage request for monitoring data to the memory management module 120 in response to a monitoring event.
[0018] Optionally, the monitoring event may be an alarm event. When the monitoring device identifies an abnormality in the monitoring area, the alarm event may be generated and a picture may be captured. The captured picture is the monitoring data with memory usage requirements. The monitoring event may be a timed capture event. In response to the timed capture event, the monitoring device may capture a picture at a preset capture interval. The captured picture is the monitoring data with memory usage requirements.
[0019] In this embodiment, the memory management module 120 is used to search for multiple continuous target memory blocks in an idle state from the circular memory pool 130 in response to a memory use request. The circular memory pool includes n memory blocks, and the first memory block in the circular memory pool is adjacent to the nth memory block, where n is an integer greater than or equal to 3. Thus, based on multiple continuous target memory blocks, and the correspondence between pre-created memory blocks and memory index information, the target memory index information corresponding to the monitoring data is determined. The target memory index information may include: the number of target memory blocks and the starting position of the target memory block in the circular memory pool. Furthermore, based on the target memory index information, the starting storage position of the monitoring data in the multiple continuous target memory blocks is determined, and based on the starting storage position, the monitoring data is stored and processed. The circular memory pool 130 is used to store monitoring data.
[0020] By adopting the memory management system provided by the embodiment of the present application, the monitoring device can send a memory usage request of the monitoring data to the memory management module in response to the monitoring event. The memory management module can search for multiple continuous target memory blocks in an idle state from the circular memory pool in response to the memory usage request, thereby determining the target memory index information corresponding to the monitoring data based on the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information. Furthermore, according to the target memory index information, the starting storage position of the monitoring data in the multiple continuous target memory blocks is determined, and the monitoring data is stored in the circular memory pool according to the starting storage position. Compared with the scheme of using the system interface to apply for and release data in the related art, in this system, on the one hand, the circular memory pool is used to store the monitoring data, which avoids the memory fragmentation generated during the storage and release of the monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. Moreover, by storing monitoring data in a plurality of continuous memory blocks in an idle state in a circular memory pool, not only the complexity of matching memory blocks for monitoring data is reduced, but also, compared with a memory pool with a unidirectional structure, if there are continuous memory blocks near the end (i.e., the nth memory block) and continuous memory blocks at the starting position (i.e., the first memory block) in the circular memory pool, which can form the above-mentioned plurality of continuous target memory blocks, the monitoring data can be stored in the circular memory pool, thereby avoiding the situation that the monitoring data cannot be stored due to the discontinuity of the idle memory blocks, wasting memory resources, and improving the utilization rate of memory resources. On the other hand, the memory index information corresponding to the monitoring data can be determined, so as to determine the starting storage position of the monitoring data according to the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when performing memory management (such as releasing memory) on the circular memory pool, the situation of the memory blocks occupied by a monitoring data can be quickly and accurately determined according to the memory index information, which is conducive to ensuring that the memory management steps are executed in a timely and accurate manner.
[0021] In one embodiment, Figure 2 As shown, the memory management system may include a processing platform 140, and the processing platform 140 is connected to the monitoring device 110 and the memory management module 120 respectively. The number of the processing platform may be one or more. Figure 2 Two processing platforms 140 are schematically shown in FIG.
[0022] In this embodiment, the monitoring device 110 is used to report the monitoring event to the processing platform 140. The processing platform can be a platform deployed for the monitoring event.
[0023] The memory management module 120 is used to send the monitoring data stored in the ring memory pool 130 to the processing platform 140. After the monitoring data is sent, the reference count corresponding to the monitoring data is updated. The initial value of the reference count is the number of processing platforms 140. When the updated reference count is zero, the target memory block occupied by the monitoring data is released. The processing platform 140 is used to process monitoring events according to the monitoring data.
[0024] In this embodiment, a reference count corresponding to the monitoring data is introduced to characterize whether the monitoring data in the ring memory pool is sent to each processing platform, and when the reference count is cleared, the release of the memory can be triggered, thereby realizing automatic and efficient management of the ring memory pool.
[0025] The following describes in detail the operations performed by the memory management module 120 during the memory application and memory release process for monitoring data.
[0026] Figure 3 is a schematic flow chart of a memory management method according to an embodiment of the present application, such as Figure 3 As shown, the method may include: S302 : In response to a memory usage request for monitoring data, searching a plurality of consecutive target memory blocks in an idle state from a ring memory pool.
[0027] The ring memory pool includes n memory blocks, the first memory block in the ring memory pool is adjacent to the nth memory block, and n is an integer greater than or equal to 3. The memory usage request is used to apply for memory space for monitoring data.
[0028] Optionally, the monitoring data may be a picture captured by the monitoring device when it identifies an abnormality in the monitoring area, or may be a picture captured by the monitoring device at a preset capture interval. When the monitoring device identifies an abnormality in the monitoring area, an alarm event may be generated, and a picture may be captured, and the captured picture may be reported to the alarm event processing platform together with the alarm event as an alarm snapshot.
[0029] Optionally, the memory blocks in the annular memory pool correspond to memory identification information, the memory identification information includes state information and attribute information of the memory block, the state information includes an occupied state or an idle state, and the attribute information may include a starting position and / or a memory capacity of the memory block. In this embodiment, it is possible to determine whether each memory block in the annular memory pool is in an idle state based on the state information of the memory block, thereby finding multiple continuous target memory blocks in an idle state.
[0030] S304: Determine the target memory index information corresponding to the monitoring data according to a plurality of continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information.
[0031] The target memory index information may include: the number of target memory blocks and the starting position of the target memory block in the annular memory pool. The starting position of the target memory block in the annular memory pool may be: the starting position of the first memory block among the multiple continuous target memory blocks.
[0032] S306: Determine the starting storage position of the monitoring data in a plurality of continuous target memory blocks according to the target memory index information.
[0033] S308, storing the monitoring data according to the initial storage position.
[0034] Adopting the technical solution of the embodiment of the present application, in response to a memory usage request for monitoring data, multiple continuous target memory blocks in an idle state are searched from a circular memory pool, the circular memory pool includes n memory blocks, and the first memory block in the circular memory pool is adjacent to the nth memory block, so as to determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information. Furthermore, according to the target memory index information, the starting storage position of the monitoring data in the multiple continuous target memory blocks is determined, and according to the starting storage position, the monitoring data is stored. Compared with the scheme of using the system interface to apply for and release data in the related art, in this technical scheme, on the one hand, the circular memory pool is used to store the monitoring data, which avoids the memory fragmentation generated during the storage and release of the monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. Moreover, by storing monitoring data in a plurality of continuous memory blocks in an idle state in a circular memory pool, not only the complexity of matching memory blocks for monitoring data is reduced, but also, compared with a memory pool with a unidirectional structure, if there are continuous memory blocks near the end (i.e., the nth memory block) and continuous memory blocks at the starting position (i.e., the first memory block) in the circular memory pool, which can form the above-mentioned plurality of continuous target memory blocks, the monitoring data can be stored in the circular memory pool, thereby avoiding the situation that the monitoring data cannot be stored due to the discontinuity of the idle memory blocks, wasting memory resources, and improving the utilization rate of memory resources. On the other hand, the memory index information corresponding to the monitoring data can be determined, so as to determine the starting storage position of the monitoring data according to the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when performing memory management (such as releasing memory) on the circular memory pool, the situation of the memory blocks occupied by a monitoring data can be quickly and accurately determined according to the memory index information, which is conducive to ensuring that the memory management steps are executed in a timely and accurate manner.
[0035] In one embodiment, before searching for a plurality of consecutive target memory blocks in an idle state from the annular memory pool in response to a memory usage request for monitoring data (ie, S302 ), the annular memory pool may be constructed through the following steps A1 to A3 .
[0036] Step A1, applying for a memory space of a specified memory capacity from the system memory.
[0037] If bytes are used as the unit of memory capacity, assuming that the specified memory capacity is 500 bytes, then this step may be executed as follows: applying for a memory space with a memory capacity of 500 bytes from the system memory.
[0038] Step A2: divide the memory space into n memory blocks according to a preset memory block division method, where n is an integer greater than or equal to 3.
[0039] Optionally, the memory block division method may be random division or equal division. In the case of random division of the memory space, the sizes of the n memory blocks are not completely consistent. In the case of equal division of the memory space, the sizes of the n memory blocks are completely consistent.
[0040] Step A3, arrange n memory blocks in sequence, and define the nth memory block to be adjacent to the first memory block, to obtain a ring memory pool.
[0041] Optionally, the ring memory pool can be used as a critical resource, and a mutex lock can be used to ensure mutually exclusive access to this resource. In this way, when applying for memory or releasing memory for monitoring data, the state of the mutex lock needs to be changed to a locked state to ensure that only memory is applied for or released for one monitoring data in the same time period, and after the memory application process or memory release process is completed, the state of the mutex lock needs to be changed to an unlocked state to allow other monitoring data to be stored in or released from the ring memory pool.
[0042] In practical applications, the ring memory pool does not refer to a memory pool that is connected end to end in a ring in the physical sense, but a ring in the logical sense. Because the memory space is a linear structure, the ring memory pool is actually still a lengthy memory space, which has the function of realizing mutual exclusive access to the memory pool by the communication process.
[0043] like Figure 4 As shown, a structure of a ring memory pool is schematically shown, wherein the nth memory block is adjacent to the first memory block and is not shown in Figure 4If the traversal direction of the memory block is defined as from the first memory block to the nth memory block, and then back to the first memory block to start traversal, forming a circular path, the starting position of the initial traversal memory block is recorded as startPos, then after traversing to the memory block with the starting position of startPos-1, if multiple consecutive target memory blocks in the idle state are still not found, the information that the memory block search failed can be returned.
[0044] In this embodiment, by constructing a circular memory pool, subsequent monitoring data can be stored in the circular memory pool, avoiding frequent calls to the system interface during the storage process of the monitoring data, reducing system overhead, and reducing the number of memory fragments. Moreover, compared with a memory pool with a one-way structure, if there are continuous memory blocks near the end (i.e., the nth memory block) plus continuous memory blocks at the starting position (i.e., the first memory block) in the circular memory pool that can form the above-mentioned multiple continuous target memory blocks, the monitoring data can be stored in the circular memory pool, avoiding the situation where the monitoring data cannot be stored due to discontinuous free memory blocks, wasting memory resources, and improving the memory resource utilization of the monitoring device.
[0045] In one embodiment, after executing step A3, the memory identification information of each memory block in the ring memory pool may be initialized.
[0046] Optionally, in the case where the memory identification information includes the state information of the memory block, the initialization content of the memory identification information may be to mark each memory block as being in an idle state. In the case where the memory identification information includes the starting position of the memory block, the initialization content of the memory identification information may be to record the starting position of each memory block. In the case where the memory identification information includes the memory capacity of the memory block, the initialization content of the memory identification information may be to record the memory capacity of each memory block.
[0047] Optionally, after the ring memory pool is initialized, the internal memory block size will no longer be adjusted.
[0048] In this embodiment, by initializing the memory identification information of each memory block in the circular memory pool, the circular memory pool is managed based on the memory identification information of multiple dimensions, which provides a data basis for accurately managing the memory blocks in the subsequent application and release of memory blocks, thereby reducing the management complexity of the circular memory pool.
[0049] In one embodiment, in response to a memory usage request for monitoring data, before searching for multiple consecutive target memory blocks in an idle state from the ring memory pool (i.e., S302), a mutex lock corresponding to the ring memory pool may be acquired, and when the state of the mutex lock is unlocked, the state of the mutex lock is modified to a locked state. Furthermore, after storing the monitoring data according to the starting storage position (i.e., S308), the state of the mutex lock needs to be modified from a locked state to an unlocked state.
[0050] In this embodiment, if the state of the acquired mutex lock is the locked state, it is necessary to wait until the state of the acquired mutex lock is the unlocked state, and then immediately modify the state of the mutex lock to the locked state to occupy the mutex lock.
[0051] In this embodiment, before applying for memory for monitoring data, by acquiring the mutex lock corresponding to the annular memory pool and modifying the state of the mutex lock to a locked state to occupy the mutex lock, it is possible to ensure mutual exclusive access to the annular memory pool. In this way, in the same time period, the annular memory pool only processes the memory application for one monitoring data, avoiding the occurrence of data storage confusion. In addition, after the memory application process is completed, by modifying the state of the mutex lock to an unlocked state, it is convenient for other monitoring data to be stored in the annular memory pool or released from the annular memory pool.
[0052] In one embodiment, the memory usage request may include the memory demand. In response to the memory usage request for the monitoring data, searching for a plurality of consecutive target memory blocks in an idle state from the ring memory pool (ie, S302) may be performed as follows: Steps B1 to B4: Optionally, before executing step B1, the legitimacy of the memory requirement of the monitoring data may be checked. If the legitimacy check of the memory requirement passes, step B1 is executed; if the legitimacy check of the memory requirement fails, information indicating that the memory block search has failed is returned.
[0053] Among them, when the memory demand is less than or equal to the total memory capacity of the ring memory pool, it can be determined that the legitimacy check of the memory demand has passed; when the memory demand is greater than the total memory capacity of the ring memory pool, it can be determined that the legitimacy check of the memory demand has failed.
[0054] Step B1: determine the first memory block in the circular memory pool that is in an idle state according to a preset memory block traversal method.
[0055] The memory block traversal method may include an initial traversal memory block and a traversal direction. The initial traversal memory block is used to determine which memory block in the circular memory pool to start traversal from. The traversal direction is used to determine the end of the traversal memory block, that is, after which memory block in the circular memory pool is traversed, the traversal is determined to end.
[0056] by Figure 4 Taking the circular memory pool shown in the figure as an example, if the initial traversal memory block is the n-1th memory block, the traversal direction is from the n-1th memory block to the nth memory block, and then returns to the first memory block to start traversal, forming a circular path, then it can be determined that the end traversal memory block is the n-2th memory block. That is, after starting from the n-1th memory block, traversing to the nth memory block, the first memory block, the second memory block in sequence until the n-2th memory block is traversed, if multiple continuous target memory blocks in the idle state are still not found, then the traversal is determined to be over. At this time, the information that the memory block search failed can be returned.
[0057] Step B2: when the memory capacity of the first memory block meets the memory requirement, determine the first memory block as the target memory block.
[0058] In this embodiment, after the target memory block is determined, the target memory index information corresponding to the monitoring data can be determined according to the target memory block and the correspondence between the pre-created memory block and the memory index information. In the target memory index information, the number of target memory blocks is 1, and the starting position of the target memory block in the ring memory pool is the starting position of the first memory block.
[0059] Step B3, when the memory capacity of the first memory block does not meet the memory demand, if the next memory block adjacent to the first memory block is in an idle state, continue to traverse the circular memory pool until the total memory capacity of multiple consecutive first memory blocks in an idle state is obtained to meet the memory demand, and determine the multiple consecutive first memory blocks as target memory blocks.
[0060] Step B4, when the memory capacity of the first memory block does not meet the memory demand, if the next memory block adjacent to the first memory block is in an occupied state, re-determine the second memory block in the circular memory pool that is in an idle state, and determine the target memory block based on the second memory block.
[0061] Optionally, the number and total memory capacity of the continuous memory blocks in the idle state can be recorded during the traversal process. In this embodiment, it can be determined whether it is necessary to continue traversing the annular memory pool by judging whether the total memory capacity recorded meets the memory demand. After determining to continue traversing the annular memory pool, the number of records and the total memory capacity are updated according to the memory capacity of the memory blocks traversed subsequently and whether they are in the idle state.
[0062] Specifically, when the next traversed memory block is in an idle state, the number of records and the total memory capacity are accumulated respectively, and it is determined again whether the updated total memory capacity meets the memory requirement. If not, the traversal is continued until the final updated total memory capacity meets the memory requirement, then the traversal is stopped and the information of successful memory block search is returned. Alternatively, in the process of continuing the traversal, until the total memory capacity updated at the end of the traversal still does not meet the memory requirement, the information of memory block search failure is returned. When the next traversed memory block is in an occupied state, the number of records and the total memory capacity are cleared respectively, and the circular memory pool is continued to be traversed to find the memory block in an idle state, and the above-mentioned steps B2 to B4 are performed on the found memory block in an idle state.
[0063] In this embodiment, based on the second memory block, the target memory block can be determined according to the following steps C1 to C3.
[0064] Step C1, when the memory capacity of the second memory block meets the memory requirement, determine the second memory block as the target memory block.
[0065] In this embodiment, after determining the target memory block, the target memory index information corresponding to the monitoring data can be determined according to the target memory block and the correspondence between the pre-created memory block and the memory index information. In the target memory index information, the number of target memory blocks is 1, and the starting position of the target memory block in the ring memory pool is the starting position of the second memory block.
[0066] Step C2, when the memory capacity of the second memory block does not meet the memory demand, if the next memory block adjacent to the second memory block is in an idle state, continue to traverse the circular memory pool until the total memory capacity of multiple consecutive second memory blocks in an idle state is obtained to meet the memory demand, and determine the multiple consecutive second memory blocks as target memory blocks.
[0067] Step C3, when the memory capacity of the second memory block does not meet the memory demand, if the next memory block adjacent to the second memory block is in an occupied state, then re-determine a third memory block in the circular memory pool that is in an idle state, and determine the target memory block based on the third memory block.
[0068] In this embodiment, the execution process of determining the target memory block based on the third memory block is similar to step C1 to step C3, which will not be repeated here.
[0069] In this embodiment, by traversing the circular memory pool to find multiple consecutive memory blocks in an idle state for storing monitoring data, the complexity of matching memory blocks for monitoring data is reduced. Compared with the memory pool with a unidirectional structure, the use of the circular memory pool to store monitoring data improves the memory resource utilization of the monitoring device.
[0070] In one embodiment, according to a plurality of continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information, determining the target memory index information corresponding to the monitoring data (i.e., S304) can be performed as follows: according to the number of the plurality of continuous target memory blocks, determining the number of target memory blocks in the target memory index information. According to the starting position of the first memory block in the plurality of continuous target memory blocks, determining the starting position of the target memory block in the target memory index information in the ring memory pool.
[0071] Among them, the correspondence between the memory blocks and the memory index information includes: the number of memory blocks corresponds to the number of memory blocks in the memory index information; the starting position of the first memory block in multiple consecutive memory blocks corresponds to the starting position of the memory block in the circular memory pool in the memory index information.
[0072] In one embodiment, determining the starting storage position of the monitoring data in multiple consecutive target memory blocks (i.e., S306) based on the target memory index information can be executed as follows: determining the starting storage position of the monitoring data in multiple consecutive target memory blocks based on the target memory index information and a preset data storage order.
[0073] Optionally, a data storage order may be set to first store the target memory index information in a plurality of consecutive target memory blocks, and then store the monitoring data after the target memory index information.
[0074] In this embodiment, the starting storage position of the monitoring data in multiple continuous target memory blocks can be determined according to the starting position of the target memory block in the circular memory pool and the memory space occupied by the target memory index information.
[0075] Optionally, the size of the memory space occupied by the memory index information may be preset. For example, the size of the memory space occupied by the memory index information is preset to be 20 bytes, and then, during the use of the ring memory pool, the size of the memory space occupied by the memory index information involved is 20 bytes.
[0076] Exemplarily, if the starting position of the target memory block in the circular memory pool is at the 10-byte position and the memory space occupied by the target memory index information is 20 bytes, then, in this embodiment, the starting position of the target memory block in the circular memory pool and the memory space occupied by the target memory index information can be accumulated to obtain the starting storage position of the monitoring data in multiple consecutive target memory blocks at the 30-byte position.
[0077] In this embodiment, after determining the starting storage position of the monitoring data in multiple consecutive target memory blocks based on the target memory index information (i.e., S306), the target memory index information can be stored with the starting position of the target memory block in the circular memory pool as the starting position of the target memory index information.
[0078] In one embodiment, after the monitoring data is stored (ie, S308 ) according to the initial storage location, the following steps D1 to D3 may be performed: Step D1, sending the monitoring data to the processing platform.
[0079] The processing platform is a processing platform for monitoring data. The number of processing platforms can be one or more. Optionally, in the case where the monitoring data is an alarm screenshot, the processing platform can be a platform for deploying defenses for the alarm events of the monitoring device.
[0080] Step D2, after the monitoring data is sent, update the reference count corresponding to the monitoring data.
[0081] The initial value of the reference count is the number of processing platforms. In this embodiment, once the monitoring data is sent out, it will trigger the update of the reference count regardless of whether it has been received by the processing platform.
[0082] Step D3, when the updated reference count is zero, release the target memory block occupied by the monitoring data.
[0083] In this embodiment, a reference count corresponding to the monitoring data is introduced to characterize whether the monitoring data in the ring memory pool is sent to each processing platform, and when the reference count is cleared, the release of the memory can be triggered, thereby realizing automatic and efficient management of the ring memory pool.
[0084] In one embodiment, after the monitoring data is stored according to the initial storage location (ie, S308 ), in response to the monitoring data being successfully stored, a storage location relationship between the target memory index information and the monitoring data may be generated.
[0085] Optionally, a storage location relationship may be generated in which the target memory index information is in front and the monitoring data is in the back.
[0086] In this embodiment, releasing the target memory block occupied by the monitoring data (ie, step D3) can be performed as follows: step D31 to step D34: Step D31, determining the starting storage location of the monitoring data.
[0087] The initial storage location of the monitoring data is the return value of the memory usage request for the monitoring data. During the memory release process, the monitoring data with memory release requirements needs to transfer the above return value to the ring memory pool.
[0088] Step D32, searching the ring memory pool for a target memory block corresponding to the starting storage position.
[0089] If the target memory block corresponding to the starting storage position cannot be found in the circular memory pool, it means that the input starting storage position is illegal. For example, the location area corresponding to the circular memory pool is 20 bytes to 100 bytes. Then, when the starting storage position is at the 10-byte position, the starting storage position is illegal because it is outside the location area corresponding to the circular memory pool. When the starting storage position is at the 50-byte position, the starting storage position is legal because it is within the location area corresponding to the circular memory pool.
[0090] Optionally, when it is determined that the incoming starting storage location is illegal, the memory release process can be terminated. In addition, a warning message such as a memory release interruption can be issued to prompt the user that the memory release has failed.
[0091] Step D33, searching the target memory index information corresponding to the monitoring data from the annular memory pool according to the found target memory block and the storage location relationship.
[0092] Optionally, when the storage position relationship is that the target memory index information is in front and the monitoring data is in the back, the search may be started from the starting storage position in the target memory block to find the target memory index information corresponding to the monitoring data.
[0093] Step D34, releasing the target memory block occupied by the monitoring data according to the target memory index information.
[0094] In this embodiment, when releasing the memory in the annular memory pool, the memory index information corresponding to the monitoring data stored in the annular memory pool and having the memory release requirement can be found first, so that the memory block occupied by the monitoring data can be quickly and accurately determined based on the memory index information, which is conducive to ensuring that the memory release step is executed in a timely and accurate manner.
[0095] In one embodiment, before executing step D31, the mutex lock corresponding to the ring memory pool may be acquired, and when the state of the mutex lock is unlocked, the state of the mutex lock is changed to locked state. And after executing step D34, the state of the mutex lock needs to be changed from locked state to unlocked state.
[0096] In this embodiment, if the state of the acquired mutex lock is the locked state, it is necessary to wait until the state of the acquired mutex lock is the unlocked state, and then immediately modify the state of the mutex lock to the locked state to occupy the mutex lock.
[0097] In this embodiment, before releasing the memory for monitoring data, the mutual exclusion lock corresponding to the annular memory pool is obtained, and the state of the mutual exclusion lock is modified to a locked state to occupy the mutual exclusion lock, so that the mutual exclusion access to the annular memory pool can be ensured. In this way, in the same time period, the annular memory pool only processes the memory release of one monitoring data, avoiding the occurrence of memory release errors. In addition, after the memory release process is completed, the state of the mutual exclusion lock is modified to an unlocked state, so that other monitoring data can be stored in the annular memory pool or released from the annular memory pool.
[0098] In one embodiment, according to the target memory index information, releasing multiple continuous target memory blocks occupied by the monitoring data (ie, step D34) may be performed as follows: step D341 to step D344: Step D341, verify the validity of the target memory index information.
[0099] Optionally, if the target memory index information satisfies the first legal condition, it may be determined that the legality check of the target memory index information has passed, and if the target memory index information does not satisfy the first legal condition, it may be determined that the legality check of the target memory index information has failed.
[0100] The first legal condition includes one or more of the following: the verification mark value of the target memory index information is a preset string; the starting position of the target memory block is located in the position area corresponding to the circular memory pool; the number of target memory blocks is less than or equal to the total number of memory blocks in the circular memory pool.
[0101] Optionally, the target memory index information has a preset check mark value, which is a preset string. By checking whether the check mark value has been tampered with, it can be determined whether memory trampling or other anomalies have occurred in the annular memory pool. Generally, if the check mark value has been tampered with, it can be determined that memory trampling or other anomalies have occurred in the annular memory pool.
[0102] Step D342, when the validity check of the target memory index information passes, the memory blocks to be released in the ring memory pool are determined according to the number of target memory blocks and the starting positions of the target memory blocks in the ring memory pool.
[0103] If the validity check of the target memory index information fails, the memory release process can be terminated. In addition, an alarm message such as a memory release interruption can be issued to prompt the user that the memory release fails.
[0104] Step D343, performing a validity check on the memory identification information of the memory block to be released.
[0105] The memory identification information includes the state information and attribute information of the memory block to be released. The state information of the memory block to be released includes the occupied state or the idle state. The attribute information of the memory block to be released includes the starting position and / or the memory capacity.
[0106] Optionally, when the memory block to be released is in an idle state, it is determined that the validity check of the memory identification information fails. When the memory block to be released is in an occupied state, if the attribute information of the memory block to be released meets the second legal condition, it is determined that the validity check of the memory identification information passes.
[0107] The second legal condition includes: the starting position of the memory block to be released is within the position area corresponding to the ring memory pool; and / or the memory capacity of the memory block to be released is less than or equal to a preset capacity threshold.
[0108] Optionally, the memory capacities of the memory blocks to be released may be the same or different. Here, by setting a capacity threshold, it can be determined whether there is a memory block whose memory capacity has been tampered with.
[0109] Step D344, when the validity check of the memory identification information passes, the memory block to be released is released.
[0110] If the validity check of the memory identification information fails, the memory release process can be terminated. In addition, an alarm message such as a memory release interruption can be issued to prompt the user that the memory release fails.
[0111] Optionally, after releasing the memory blocks to be released, the state information of these memory blocks may be marked as idle, so that other monitoring data can utilize these idle resources in the subsequent memory application process.
[0112] In the present embodiment, by performing a validity check on the target memory index information, it is possible to effectively avoid releasing the memory blocks occupied by the monitoring data whose target memory index information has problems. Only when the validity check on the target memory index information passes, the memory blocks to be released in the circular memory pool are determined according to the number of target memory blocks and the starting position of the target memory blocks in the circular memory pool, and a validity check is performed on the memory identification information of the memory blocks to be released, thereby further avoiding releasing the memory blocks to be released whose memory identification information has problems, thereby increasing the possibility of memory faults being discovered by users, which is conducive to avoiding further memory application and memory release for the faulty circular memory pool.
[0113] The specific steps of memory application and memory release in the memory management method provided in the embodiment of the present application are described in detail below. Figure 5 is a schematic flow chart of a memory application process according to an embodiment of the present application, such as Figure 5 As shown, the method may include: S501, in response to a memory usage request for monitoring data, determine whether the memory requirement of the monitoring data is legal; if not, execute S502; if yes, execute S503.
[0114] Wherein, when the total memory capacity of the annular memory pool is greater than or equal to the memory demand, the memory demand is determined to be legal, and when the total memory capacity of the annular memory pool is less than the memory demand, the memory demand is determined to be illegal.
[0115] Optionally, before executing S501, a mutex lock corresponding to the annular memory pool may be acquired, and when the state of the mutex lock is unlocked, the state of the mutex lock may be changed to a locked state to ensure mutually exclusive access to the annular memory pool.
[0116] S502, returning information that the memory block search failed, and then ending the memory application process.
[0117] S503: traverse the memory blocks in the circular memory pool according to a preset memory block traversal method.
[0118] The memory block traversal method may include an initial traversal memory block and a traversal direction.
[0119] S504, determine whether the traversal is completed; if so, execute S505; if not, execute S506.
[0120] The end of the traversal may be determined when the last memory block in the traversal direction is traversed.
[0121] S505, returning information that the memory block search failed, and then ending the memory application process.
[0122] S506, determine whether the currently traversed memory block is in an idle state; if not, execute S507; if so, execute S508.
[0123] S507, clearing the total memory capacity of the recorded continuous memory blocks in the idle state to zero. Then, returning to S503.
[0124] S508: Update the total memory capacity of the recorded continuous memory blocks in the idle state.
[0125] S509, determine whether the total memory capacity meets the memory requirement of the monitoring data; if so, execute S510; if not, return to execute S503.
[0126] S510, determining that a plurality of consecutive target memory blocks in an idle state are found.
[0127] S511, determining target memory index information corresponding to the monitoring data according to a plurality of continuous target memory blocks and a correspondence between pre-created memory blocks and memory index information.
[0128] The target memory index information includes: the number of target memory blocks and the starting position of the target memory block in the ring memory pool.
[0129] S512, determining the starting storage position of the monitoring data in a plurality of continuous target memory blocks according to the target memory index information and a preset data storage order.
[0130] The data storage order is the storage order of the target memory index information and the monitoring data in multiple consecutive target memory blocks.
[0131] S513, storing the monitoring data according to the initial storage position.
[0132] S514, storing the target memory index information according to the data storage order.
[0133] Optionally, after executing S514, the state of the mutex lock needs to be changed from a locked state to an unlocked state, so that other monitoring data can be stored in the annular memory pool or released from the annular memory pool.
[0134] The specific process of S501-S514 has been described in detail in the above embodiment and will not be repeated here.
[0135] The technical solution of the embodiment of the present application is adopted, compared with the solution of using the system interface to apply for data in the related art, on the one hand, the monitoring data is stored by using the circular memory pool, which avoids the memory fragmentation generated during the storage and release of the monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. In addition, the monitoring data is stored by using multiple continuous memory blocks in the idle state in the circular memory pool, which not only reduces the complexity of matching memory blocks for monitoring data, but also, compared with the memory pool of the unidirectional structure, if there are continuous memory blocks near the end (i.e., the nth memory block) in the circular memory pool plus continuous memory blocks at the starting position (i.e., the first memory block) to form the above-mentioned multiple continuous target memory blocks, then the monitoring data can be stored in the circular memory pool, avoiding the situation that the monitoring data cannot be stored due to the discontinuity of the idle memory blocks, wasting memory resources, and improving the utilization rate of memory resources. On the other hand, the memory index information corresponding to the monitoring data can be determined, so as to determine the starting storage position of the monitoring data according to the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when performing memory management on the circular memory pool (such as releasing memory), the memory block occupied by a monitoring data can be quickly and accurately determined according to the memory index information, which is conducive to ensuring that the memory management steps are executed in a timely and accurate manner.
[0136] Figure 6 is a schematic flow chart of a memory release process according to an embodiment of the present application, such as Figure 6 As shown, the method includes: S601, determine whether the starting storage location of the monitoring data passed into the ring memory pool is legal; if so, execute S602; if not, execute S607.
[0137] Optionally, the incoming starting storage position may be determined to be legal if the incoming starting storage position is within the location area corresponding to the annular memory pool, or may be determined to be illegal if the incoming starting storage position is outside the location area corresponding to the annular memory pool.
[0138] Optionally, before executing S601, a mutex lock corresponding to the annular memory pool may be acquired, and when the state of the mutex lock is unlocked, the state of the mutex lock may be changed to a locked state to ensure mutually exclusive access to the annular memory pool.
[0139] S602: Search the target memory index information corresponding to the monitoring data from the ring memory pool according to the target memory index information corresponding to the monitoring data and the storage location relationship of the monitoring data.
[0140] The target memory index information and the storage location relationship of the monitoring data are generated in response to the successful storage of the monitoring data. The target memory index information includes the number of target memory blocks and the starting position of the target memory block in the ring memory pool.
[0141] S603, determine whether the target memory index information is legal; if so, execute S604; if not, execute S607.
[0142] S604: Determine the memory blocks to be released in the ring memory pool according to the number of target memory blocks and the starting positions of the target memory blocks in the ring memory pool.
[0143] S605, determine whether the memory identification information of the memory block to be released is legal; if so, execute S606; if not, execute S607.
[0144] The memory identification information includes the state information and attribute information of the memory block to be released. The state information of the memory block to be released includes the occupied state or the idle state. The attribute information of the memory block to be released includes the starting position and / or the memory capacity.
[0145] S606, releasing the memory block to be released.
[0146] After releasing the memory blocks to be released, the status information of these memory blocks can be marked as idle, so that other monitoring data can use these idle resources in the subsequent memory application process.
[0147] S607, end the memory release process.
[0148] Optionally, after executing S607 , the state of the mutex lock needs to be changed from a locked state to an unlocked state, so that other monitoring data can be stored in the annular memory pool or released from the annular memory pool.
[0149] The specific process of S601-S607 has been described in detail in the above embodiment and will not be repeated here.
[0150] Compared with the scheme of using system interface to apply for and release data in the related art, the technical scheme of the embodiment of the present application adopts, on the one hand, the use of a circular memory pool to store monitoring data avoids the memory fragmentation generated during the storage and release of monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. On the other hand, it is possible to determine the memory index information corresponding to the monitoring data, thereby determining the starting storage position of the monitoring data based on the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when executing the memory release process on the circular memory pool, the situation of the memory block occupied by a monitoring data can be quickly and accurately determined based on the memory index information, which is conducive to ensuring that the memory release step is executed in a timely and accurate manner.
[0151] In summary, specific embodiments of the present subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recorded in the claims can be performed in a different order and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing can be advantageous.
[0152] The above is the memory management method provided in the embodiment of the present application. Based on the same idea, the embodiment of the present application also provides a memory management device.
[0153] Figure 7 is a schematic block diagram of a memory management device according to an embodiment of the present application. Figure 7 , the memory management device may include: A search module 710 is used to search for a plurality of consecutive target memory blocks in an idle state from a ring memory pool in response to a memory usage request for monitoring data; the ring memory pool includes n memory blocks, and a first memory block in the ring memory pool is adjacent to an nth memory block; n is an integer greater than or equal to 3; The first determination module 720 is used to determine the target memory index information corresponding to the monitoring data according to a plurality of continuous target memory blocks and a correspondence between the pre-created memory blocks and the memory index information; the target memory index information includes: the number of target memory blocks and the starting position of the target memory block in the ring memory pool; A second determination module 730, configured to determine a starting storage position of the monitoring data in a plurality of continuous target memory blocks according to the target memory index information; The storage module 740 is used to store the monitoring data according to the initial storage location.
[0154] In one embodiment, the memory management device further includes: A sending module, used for storing the monitoring data according to the initial storage location and then sending the monitoring data to the processing platform; A reference count update module is used to update the reference count corresponding to the monitoring data after the monitoring data is sent; the initial value of the reference count is the number of processing platforms; The memory block release module is used to release the target memory block occupied by the monitoring data when the updated reference count is zero.
[0155] In one embodiment, the memory management device further includes: A generating module, configured to generate a target memory index information and a storage location relationship of the monitoring data in response to successful storage of the monitoring data after storing the monitoring data according to the starting storage location; The memory block release module includes: A first determining unit, used to determine a starting storage location of monitoring data; A first search unit, used for searching a target memory block corresponding to a starting storage position in the ring memory pool; A second search unit is used to search the target memory index information corresponding to the monitoring data from the ring memory pool according to the found target memory block and the storage position relationship; The memory block releasing unit is used to release the target memory block occupied by the monitoring data according to the target memory index information.
[0156] In one embodiment, the memory block release unit is specifically used for: Perform a validity check on the target memory index information; When the validity check of the target memory index information passes, the memory blocks to be released in the ring memory pool are determined according to the number of the target memory blocks and the starting positions of the target memory blocks in the ring memory pool; Performing a validity check on the memory identification information of the memory block to be released; the memory identification information includes the state information and attribute information of the memory block to be released; the state information of the memory block to be released includes the occupied state or the idle state; the attribute information of the memory block to be released includes the starting position and / or the memory capacity; When the validity check of the memory identification information passes, the memory block to be released is released.
[0157] In one embodiment, the memory block release unit is specifically used for: In the case where the target memory index information satisfies the first legal condition, determining that the legality check of the target memory index information passes; The first legal condition includes one or more of the following: the verification mark value of the target memory index information is a preset string; the starting position of the target memory block is located in the position area corresponding to the circular memory pool; the number of target memory blocks is less than or equal to the total number of memory blocks in the circular memory pool.
[0158] In one embodiment, the memory block release unit is specifically used for: When the memory block to be released is in an idle state, determining that the validity check of the memory identification information fails; In the case where the memory block to be released is in an occupied state, if the attribute information of the memory block to be released satisfies the second legal condition, determining that the legality check of the memory identification information passes; The second legal condition includes: the starting position of the memory block to be released is within the position area corresponding to the ring memory pool; and / or the memory capacity of the memory block to be released is less than or equal to a preset capacity threshold.
[0159] In one embodiment, the memory usage request includes a memory demand amount; The search module 710 includes: A second determining unit is used to determine a first memory block in an idle state in the circular memory pool according to a preset memory block traversal method; the memory block traversal method includes an initial traversal memory block and a traversal direction; A third determining unit, configured to determine the first memory block as a target memory block when the memory capacity of the first memory block meets the memory requirement; a fourth determining unit, configured to, when the memory capacity of the first memory block does not meet the memory demand, continue to traverse the circular memory pool if the next memory block adjacent to the first memory block is in an idle state, until a total memory capacity of a plurality of consecutive first memory blocks in an idle state is obtained that meets the memory demand, and determine the plurality of consecutive first memory blocks as target memory blocks; The fifth determination unit is used to, when the memory capacity of the first memory block does not meet the memory demand, if the next memory block adjacent to the first memory block is in an occupied state, re-determine a second memory block in an idle state in the circular memory pool, and determine the target memory block based on the second memory block.
[0160] In one embodiment, the memory management device further includes: an acquisition module, configured to acquire a mutex lock corresponding to the annular memory pool before searching for a plurality of consecutive target memory blocks in an idle state from the annular memory pool in response to a memory usage request for monitoring data; A first modification module is used to modify the state of the mutex lock to a locked state when the state of the mutex lock is an unlocked state; The second modification module is used to modify the state of the mutex lock from a locked state to an unlocked state after storing the monitoring data according to the initial storage position.
[0161] Adopting the technical solution of the embodiment of the present application, in response to a memory usage request for monitoring data, multiple continuous target memory blocks in an idle state are searched from a circular memory pool, the circular memory pool includes n memory blocks, and the first memory block in the circular memory pool is adjacent to the nth memory block, so as to determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information. Furthermore, according to the target memory index information, the starting storage position of the monitoring data in the multiple continuous target memory blocks is determined, and according to the starting storage position, the monitoring data is stored. Compared with the scheme of using the system interface to apply for and release data in the related art, in this technical scheme, on the one hand, the circular memory pool is used to store the monitoring data, which avoids the memory fragmentation generated during the storage and release of the monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. Moreover, by storing monitoring data in a plurality of continuous memory blocks in an idle state in a circular memory pool, not only the complexity of matching memory blocks for monitoring data is reduced, but also, compared with a memory pool with a unidirectional structure, if there are continuous memory blocks near the end (i.e., the nth memory block) and continuous memory blocks at the starting position (i.e., the first memory block) in the circular memory pool, which can form the above-mentioned plurality of continuous target memory blocks, the monitoring data can be stored in the circular memory pool, thereby avoiding the situation that the monitoring data cannot be stored due to the discontinuity of the idle memory blocks, wasting memory resources, and improving the utilization rate of memory resources. On the other hand, the memory index information corresponding to the monitoring data can be determined, so as to determine the starting storage position of the monitoring data according to the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when performing memory management (such as releasing memory) on the circular memory pool, the situation of the memory blocks occupied by a monitoring data can be quickly and accurately determined according to the memory index information, which is conducive to ensuring that the memory management steps are executed in a timely and accurate manner.
[0162] Those skilled in the art should understand that Figure 7 The memory management device in can be used to implement the memory management method described above, and the detailed description thereof should be similar to the description of the method part above. To avoid tediousness, it will not be repeated here.
[0163] Based on the same idea, the embodiment of the present application also provides a memory management device, such as Figure 8As shown. The memory management device may have relatively large differences due to different configurations or performances, and may include one or more processors 801 and memory 802, and one or more applications or data may be stored in the memory 802. Among them, the memory 802 can be a short-term storage or a persistent storage. The application stored in the memory 802 may include one or more modules (not shown in the figure), and each module may include a series of computer executable instructions in the memory management device. Furthermore, the processor 801 can be configured to communicate with the memory 802 and execute a series of computer executable instructions in the memory 802 on the memory management device. The memory management device may also include one or more power supplies 803, one or more wired or wireless network interfaces 804, one or more input and output interfaces 805, and one or more keyboards 806.
[0164] Specifically, in this embodiment, the memory management device includes a memory and one or more applications, wherein the one or more applications are stored in the memory, and the one or more applications may include one or more modules, and each module may include a series of computer executable instructions in the memory management device, and the one or more applications are configured to be executed by one or more processors, including the following computer executable instructions: In response to a memory usage request for monitoring data, searching a plurality of consecutive target memory blocks in an idle state from a ring memory pool; the ring memory pool includes n memory blocks, a first memory block in the ring memory pool is adjacent to an nth memory block; n is an integer greater than or equal to 3; Determine the target memory index information corresponding to the monitoring data according to a plurality of continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information; the target memory index information includes: the number of target memory blocks and the starting position of the target memory block in the ring memory pool; Determine the starting storage position of the monitoring data in a plurality of continuous target memory blocks according to the target memory index information; Store the monitoring data according to the initial storage location.
[0165] Adopting the technical solution of the embodiment of the present application, in response to a memory usage request for monitoring data, multiple continuous target memory blocks in an idle state are searched from a circular memory pool, the circular memory pool includes n memory blocks, and the first memory block in the circular memory pool is adjacent to the nth memory block, so as to determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information. Furthermore, according to the target memory index information, the starting storage position of the monitoring data in the multiple continuous target memory blocks is determined, and according to the starting storage position, the monitoring data is stored. Compared with the scheme of using the system interface to apply for and release data in the related art, in this technical scheme, on the one hand, the circular memory pool is used to store the monitoring data, which avoids the memory fragmentation generated during the storage and release of the monitoring data, reduces the risk of memory leakage, and thus avoids affecting the memory storage performance of the monitoring device. Moreover, by storing monitoring data in a plurality of continuous memory blocks in an idle state in a circular memory pool, not only the complexity of matching memory blocks for monitoring data is reduced, but also, compared with a memory pool with a unidirectional structure, if there are continuous memory blocks near the end (i.e., the nth memory block) and continuous memory blocks at the starting position (i.e., the first memory block) in the circular memory pool, which can form the above-mentioned plurality of continuous target memory blocks, the monitoring data can be stored in the circular memory pool, thereby avoiding the situation that the monitoring data cannot be stored due to the discontinuity of the idle memory blocks, wasting memory resources, and improving the utilization rate of memory resources. On the other hand, the memory index information corresponding to the monitoring data can be determined, so as to determine the starting storage position of the monitoring data according to the memory index information, which provides a data basis for efficiently managing the memory blocks in the circular memory pool. Based on this, when performing memory management (such as releasing memory) on the circular memory pool, the situation of the memory blocks occupied by a monitoring data can be quickly and accurately determined according to the memory index information, which is conducive to ensuring that the memory management steps are executed in a timely and accurate manner.
[0166] An embodiment of the present application also proposes a storage medium, which stores one or more computer programs, and the one or more computer programs include computer executable instructions. When the computer executable instructions are executed by an electronic device including multiple applications, the electronic device can perform the various processes of the above-mentioned memory management method embodiment and achieve the same technical effect. To avoid repetition, they are not repeated here.
[0167] The embodiment of the present application also proposes a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the various processes of the above-mentioned memory management method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0168] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0169] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0170] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0171] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0172] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0173] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0174] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0175] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0176] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0177] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0178] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0179] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0180] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A memory management method, characterized in that: include: In response to a memory usage request for monitoring data, searching for a plurality of continuous target memory blocks in an idle state from a ring memory pool; The annular memory pool includes n memory blocks, and the first memory block in the annular memory pool is adjacent to the nth memory block; n is an integer greater than or equal to 3; Determine the target memory index information corresponding to the monitoring data according to the multiple continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information; The target memory index information includes: the number of the target memory blocks and the starting position of the target memory block in the ring memory pool; Determining, according to the target memory index information, a starting storage position of the monitoring data in the plurality of continuous target memory blocks; The monitoring data is stored according to the initial storage location.
2. The method according to claim 1, characterized in that After storing the monitoring data according to the initial storage location, the method further includes: Sending the monitoring data to a processing platform; After the monitoring data is sent, a reference count corresponding to the monitoring data is updated; the initial value of the reference count is the number of the processing platforms; When the updated reference count is zero, the target memory block occupied by the monitoring data is released.
3. The method according to claim 2, characterized in that After storing the monitoring data according to the initial storage location, the method further includes: In response to the monitoring data being successfully stored, generating a storage location relationship between the target memory index information and the monitoring data; The releasing the target memory block occupied by the monitoring data comprises: Determining the starting storage location of the monitoring data; Searching the target memory block corresponding to the starting storage position in the annular memory pool; According to the found target memory block and the storage location relationship, searching the target memory index information corresponding to the monitoring data from the annular memory pool; According to the target memory index information, the target memory block occupied by the monitoring data is released.
4. The method according to claim 3, characterized in that The releasing the multiple continuous target memory blocks occupied by the monitoring data according to the target memory index information includes: Performing a validity check on the target memory index information; In a case where the legitimacy check of the target memory index information passes, determining the memory blocks to be released in the annular memory pool according to the number of the target memory blocks and the starting positions of the target memory blocks in the annular memory pool; Performing a validity check on the memory identification information of the memory block to be released; the memory identification information includes the state information and attribute information of the memory block to be released; the state information of the memory block to be released includes the occupied state or the idle state; the attribute information of the memory block to be released includes the starting position and / or the memory capacity; When the validity check of the memory identification information passes, the memory block to be released is released.
5. The method according to claim 4, characterized in that The checking the validity of the target memory index information includes: In a case where the target memory index information satisfies a first legal condition, determining that a legality check of the target memory index information passes; The first legal condition includes one or more of the following: the verification mark value of the target memory index information is a preset string; the starting position of the target memory block is located in the position area corresponding to the annular memory pool; the number of the target memory blocks is less than or equal to the total number of memory blocks in the annular memory pool.
6. The method according to claim 4, characterized in that The checking the legitimacy of the memory identification information of the memory block to be released includes: When the memory block to be released is in an idle state, determining that the validity check of the memory identification information fails; In the case where the memory block to be released is in an occupied state, if the attribute information of the memory block to be released meets the second legal condition, determining that the legality check of the memory identification information passes; The second legal condition includes: the starting position of the memory block to be released is within the position area corresponding to the annular memory pool; and / or the memory capacity of the memory block to be released is less than or equal to a preset capacity threshold.
7. The method according to claim 1, characterized in that The memory usage request includes a memory requirement; The step of searching, in response to a memory usage request for monitoring data, a plurality of continuous target memory blocks in an idle state from a ring memory pool comprises: Determine the first memory block in the circular memory pool that is in an idle state according to a preset memory block traversal method; the memory block traversal method includes an initial traversal memory block and a traversal direction; In a case where the memory capacity of the first memory block meets the memory requirement, determining the first memory block as the target memory block; In the case that the memory capacity of the first memory block does not meet the memory requirement, if the next memory block adjacent to the first memory block is in an idle state, continue to traverse the annular memory pool until the total memory capacity of multiple consecutive first memory blocks in an idle state is obtained to meet the memory requirement, and determine the multiple consecutive first memory blocks as the target memory blocks; In the case that the memory capacity of the first memory block does not meet the memory requirement, if the next memory block adjacent to the first memory block is in an occupied state, a second memory block in an idle state in the circular memory pool is re-determined, and the target memory block is determined based on the second memory block.
8. The method according to claim 1, characterized in that Before searching for a plurality of consecutive target memory blocks in an idle state from the annular memory pool in response to a memory usage request for monitoring data, the method further includes: Obtain the mutex lock corresponding to the ring memory pool; When the state of the mutex lock is an unlocked state, modifying the state of the mutex lock to a locked state; After storing the monitoring data according to the starting storage position, the method further includes: modifying the state of the mutex lock from the locked state to the unlocked state.
9. A memory management device, characterized in that: include: A search module, configured to search for a plurality of continuous target memory blocks in an idle state from a ring memory pool in response to a memory usage request for monitoring data; The annular memory pool includes n memory blocks, and the first memory block in the annular memory pool is adjacent to the nth memory block; n is an integer greater than or equal to 3; A first determination module, configured to determine the target memory index information corresponding to the monitoring data according to the plurality of continuous target memory blocks and the correspondence between the pre-created memory blocks and the memory index information; The target memory index information includes: the number of the target memory blocks and the starting position of the target memory block in the ring memory pool; A second determination module, configured to determine, according to the target memory index information, a starting storage position of the monitoring data in the plurality of continuous target memory blocks; A storage module is used to store the monitoring data according to the starting storage position.
10. A memory management system, characterized in that: It includes monitoring devices, memory management modules and ring memory pools connected in sequence; wherein, The monitoring device is used to send a memory usage request for monitoring data to the memory management module in response to a monitoring event; The memory management module is used to search for multiple continuous target memory blocks in an idle state from the annular memory pool in response to the memory use request; the annular memory pool includes n memory blocks, and the first memory block in the annular memory pool is adjacent to the nth memory block; n is an integer greater than or equal to 3; according to the multiple continuous target memory blocks, and the correspondence between the pre-created memory blocks and the memory index information, determine the target memory index information corresponding to the monitoring data; the target memory index information includes: the number of the target memory blocks and the starting position of the target memory block in the annular memory pool; according to the target memory index information, determine the starting storage position of the monitoring data in the multiple continuous target memory blocks; according to the starting storage position, perform storage processing on the monitoring data; The annular memory pool is used to store the monitoring data.
11. The system according to claim 10, characterized in that The memory management system further comprises a processing platform; the processing platform is connected to the monitoring device and the memory management module respectively; The monitoring device is used to report the monitoring event to the processing platform; The memory management module is further used to send the monitoring data stored in the ring memory pool to the processing platform; after the monitoring data is sent, update the reference count corresponding to the monitoring data; the initial value of the reference count is the number of the processing platforms; when the updated reference count is zero, release the target memory block occupied by the monitoring data; The processing platform is used to process the monitoring event according to the monitoring data.
12. A memory management device, characterized in that: include: processor; as well as A memory arranged to store computer executable instructions, wherein the computer executable instructions are configured to be executed by the processor, and the computer executable instructions are executed by the processor to implement the memory management method according to any one of claims 1 to 8.
13. A storage medium, characterized in that: The storage medium is used to store computer executable instructions, and when the computer executable instructions are executed by a processor, the memory management method according to any one of claims 1 to 8 is implemented.
14. A computer program product, characterized in that It comprises a computer program, which implements the memory management method according to any one of claims 1 to 8 when executed by a processor.