A shared memory management method and cache service component

Through the cache service components and shared memory management methods, the problem of unstable data storage in graphical intelligent visual software is solved, independent and asynchronous storage of data storage functions are realized, and the stability and maintenance simplicity of the system are improved.

CN114327942BActive Publication Date: 2025-08-19BEIJING LUSTER LIGHTTECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111595898.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2025-08-19
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

The existing graphical intelligent vision software has equipment alarm problems caused by unstable data storage time and frequent external interface operations at the project site, which increases the difficulty of project implementation.

Method used

It provides a cache service component and shared memory management method, which separates the data storage function from graphical intelligent visual software, and realizes the allocation and release of data in virtual memory through cache allocator and data item queue manager. It adopts an asynchronous storage mechanism to store data in shared memory and save it by the file system.

Benefits of technology

While the external interface is frequently operated, the graphical intelligent vision software is maintained to prevent equipment alarms and simplify the difficulty of project maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327942B_ABST
    Figure CN114327942B_ABST
Patent Text Reader

Abstract

The present application discloses a shared memory management method and cache service component, wherein the cache service component includes: a cache allocator and a data item queue manager; the cache allocator is used to allocate and release virtual memory; the data item queue manager is used to record the location of data in the cache allocator in the virtual memory and the total size of the data items; the cache allocator includes: a first header area and a data area, the first header area is used to record the offset and size of the allocated virtual memory, the data area includes multiple equally divided memory blocks, the memory blocks are used to record the data placed in the virtual memory; the data item queue manager includes: a second header area and an element area, the second header area is connected to the element area, the element area includes a circular queue, the circular queue is used to record the starting offset and total size of the data items, and the second header area is used to record the characteristic information of the circular queue. The present application discloses a technical solution that can independently save images and is simple to operate and easy to maintain.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of shared memory technology, and in particular to a memory management method and a cache service component. Background Art

[0002] Existing graphical intelligent vision software (such as VISIONAssembly) supports functions such as database storage, online data statistics and report output. It can provide hundreds of image processing tools such as positioning, detection, measurement, calibration, alignment, and code reading. It can quickly build complex industrial applications through visual process programming.

[0003] The existing graphical intelligent vision software has problems such as unstable data storage time (such as image data, text data, table data, etc.) and frequent external interface operations at the project site, resulting in problems such as extended overall process running time and equipment alarms caused by timeouts, which brings maintenance difficulties to users and increases the difficulty of project implementation. Summary of the Invention

[0004] The present application provides a cache service component and a shared memory management method, which can solve problems such as unstable data storage time and device alarms, and separate the data storage function from the graphical intelligent vision software so that the graphical intelligent vision software will not be affected when the external interface is frequently operated.

[0005] In a first aspect, the present application illustrates a shared memory management method, which includes: obtaining virtual memory usage data; the virtual memory includes multiple memory blocks; judging whether the virtual memory contains only one continuous memory block based on the virtual memory usage data; if the number of occupied continuous memory blocks in the virtual memory is equal to 1, executing a cache allocation algorithm to store first data, which may be a single data stored at the same time, or a plurality of data stored at the same time.

[0006] In some embodiments, the method further includes: obtaining the starting offset of the first data based on the virtual memory usage data; determining whether the sum of the data offset of the first data and the memory capacity of the first data is greater than the memory capacity allocated by the virtual memory, and if the sum of the data offset of the first data and the memory capacity of the first data is greater than the memory capacity allocated by the virtual memory, performing error processing; if the sum of the data offset of the first data and the memory capacity of the first data is less than or equal to the memory capacity allocated by the virtual memory, obtaining the starting offset of the first data to release the memory capacity of the first data.

[0007] In some embodiments, the virtual memory usage data includes: the total capacity of memory blocks, the starting offset of the occupied memory blocks and the memory capacity of the occupied memory blocks; the execution of the cache allocation algorithm to store the first data includes: obtaining the memory capacity of the unoccupied memory blocks based on the total capacity of the memory blocks, the starting offset of the occupied memory blocks and the memory capacity of the occupied memory blocks; screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data; if the unoccupied memory blocks contain unoccupied continuous memory blocks that can store the first data, the first data is stored in the unoccupied continuous memory blocks; if the unoccupied memory blocks do not contain continuous memory blocks that can store the first data, the first data is stored in the memory block behind the last continuous memory block in the occupied continuous memory blocks; if overflow occurs after storage, error processing is performed; if no overflow occurs after storage, the first data is returned to the starting offset.

[0008] In some embodiments, the filtering of unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes: when the occupied continuous memory blocks in the virtual memory are equal to 1, obtaining the memory capacity of the unoccupied continuous memory blocks; if the memory capacity of the unoccupied continuous memory blocks is greater than or equal to the memory capacity of the first data, storing the first data in the unoccupied continuous memory blocks.

[0009] In some embodiments, the screening of unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes: when the number of occupied continuous memory blocks in the virtual memory is greater than 1, obtaining the memory capacity of the unoccupied continuous memory blocks; if the memory capacity of the unoccupied continuous memory blocks is equal to the memory capacity of the first data, storing the first data in an unoccupied continuous memory block equal to the memory capacity of the first data, and merging the continuous memory block occupied by the first data with the continuous memory blocks on both sides, and updating the number of continuous memory blocks in the virtual memory.

[0010] In some embodiments, the screening of unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes: when the number of occupied continuous memory blocks in the virtual memory is greater than 1, obtaining the memory capacity of the unoccupied continuous memory blocks; if the memory capacity of the unoccupied continuous memory blocks is greater than the memory capacity of the first data, selecting the unoccupied continuous memory block in the unoccupied continuous memory blocks whose memory capacity has the smallest difference with the memory capacity of the first data; storing the first data in the selected unoccupied continuous memory blocks, and merging the continuous memory block occupied by the first data with the continuous memory block adjacent to its left.

[0011] In some embodiments, obtaining the starting offset of the first data to release the memory capacity of the first data includes: traversing the occupied continuous memory blocks in the virtual memory to obtain the starting offset of the first data; if the starting offset of the first data is at the starting position of any of the continuous memory blocks and the memory capacity of the first data is equal to the memory capacity of the continuous memory block, deleting the continuous memory block to release the first data; if the starting offset of the first data is at the starting position of any of the continuous memory blocks and the memory capacity of the first data is less than the memory capacity of the continuous memory block, modifying the memory capacity of the last memory block of the continuous memory block to release the first data; if the starting offset of the first data is at the middle position of any of the continuous memory blocks and the memory capacity of the first data is less than the memory capacity of the continuous memory block, splitting the continuous memory block and inserting a new continuous memory block to release the first data; if the starting offset of the first data is at the right position of any of the continuous memory blocks and the memory capacity of the first memory block of the first data is less than the memory capacity of a single memory block, modifying the memory capacity of the single memory block occupied by the first memory block of the first data to release the first data.

[0012] In the second aspect, the present application also shows a cache service component for executing any of the shared memory management methods described above, the cache service component including: a cache allocator and a data item queue manager; wherein the cache allocator is used to allocate and release virtual memory; the data item queue manager is used to record the position of the data in the cache allocator in the virtual memory and the total size of the data items; the cache allocator includes: a first header area and a data area, the first header area is connected to the data area, the first header area is used to record the offset and size of the allocated virtual memory, the data area includes a plurality of equally divided memory blocks, the memory blocks are used to record the data placed in the virtual memory; the data item queue manager includes: a second header area and an element area, the second header area is connected to the element area, the element area includes a circular queue, the circular queue is used to record the starting offset and total size of the data item, and the second header area is used to record the characteristic information of the circular queue.

[0013] In some embodiments, the capacity of each of the memory blocks is preferably 64KB.

[0014] The technical solution shown above shows a shared memory management method and a cache service component. The cache service component shown in this application is essentially an asynchronous storage mechanism. The data to be saved is stored in the shared memory, and then the file system takes out the data from the shared memory for saving, so as to separate the data saving function from the graphical intelligent vision software, and can operate the external interface frequently without affecting the graphical intelligent vision software. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0016] Figure 1 shows a schematic diagram of cache service components according to some embodiments;

[0017] Figure 2 A schematic flow chart of a shared memory management method according to some embodiments is shown;

[0018] Figure 3 shows a case where the memory capacity of the first data is equal to an unoccupied continuous memory block according to some embodiments;

[0019] Figure 4 shows a situation where the memory capacity of the first data is smaller than the unoccupied continuous memory block according to some embodiments;

[0020] Figure 5 shows a case where the starting offset of the first data is located at the starting position of the memory block according to some embodiments;

[0021] Figure 6 Another case where the starting offset of the first data is located at the beginning of the memory block according to some embodiments is shown;

[0022] Figure 7 shows a case where the starting offset of the first data is located in the middle of the memory block according to some embodiments;

[0023] Figure 8 It shows a situation where the starting offset of the first data is located at the right side of the memory block according to some embodiments. DETAILED DESCRIPTION

[0024] In order to make the purpose and implementation of this application clearer, the exemplary implementation of this application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of this application. Obviously, the described exemplary embodiments are only part of the embodiments of this application, not all of the embodiments.

[0025] It should be noted that the brief descriptions of terms in this application are only for the purpose of facilitating the understanding of the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their ordinary and usual meanings.

[0026] In the specification and claims of this application and the accompanying drawings, the terms "first," "second," "third," etc. are used to distinguish similar or similar objects or entities, and are not necessarily intended to limit a particular order or sequence, unless otherwise noted. It should be understood that the terms used in this manner are interchangeable under appropriate circumstances.

[0027] Figure 1 A cache service component is shown in this application, and the cache service component includes: a cache allocator and a data item queue manager;

[0028] The cache allocator is used for allocating and releasing virtual memory; the data item queue manager is used for recording the location of the data in the cache allocator in the virtual memory and the total size of the data items;

[0029] The cache allocator includes: a first header area and a data area, wherein the first header area is connected to the data area, the first header area is used to record the offset and size of the allocated virtual memory, the data area includes a plurality of equally divided memory blocks, and the memory blocks are used to record the data placed in the virtual memory;

[0030] The data item queue manager includes: a second header area and an element area, the second header area is connected to the element area, the element area includes a circular queue, the circular queue is used to record the starting offset and total size of the data item, and the second header area is used to record characteristic information of the circular queue.

[0031] In some embodiments, the first header region is as follows Figure 1 In the area shown, the first header area can record the total capacity of the virtual memory in the entire cache allocator, the offset and size of the allocated virtual memory, and the memory capacity occupied by the first header area in the virtual memory. The data area includes multiple equally divided memory blocks, and the capacity of each memory block is preferably 64KB. The first header area can use the GsCapacityData data structure to record the above data. The size of the allocated memory recorded in this data structure is expressed as an integer multiple of 64KB.

[0032] In a specific implementation, the total capacity of the virtual memory in the entire cache allocator is 2GB, and the memory capacity occupied by the first header area in the virtual memory is 256KB; if the capacity of each memory block is set to 64KB, an arrangement of memory blocks of M rows and N columns is formed in the data area; wherein M is a positive integer greater than or equal to 1, and N is a positive integer greater than or equal to 1; the examples in this application all take image data as examples, but the data that can be stored by the technical solution shown in this application includes but is not limited to image data.

[0033] If four image data of 30KB, 60KB, 120KB, and 128KB are stored in the virtual memory at the same time, then since multiple images are stored simultaneously, the image data can be randomly stored in the data area. The 30KB image data can be stored in the memory block in the first row and first column; the 60KB image data can be stored in the memory block in the second row and second column; the 120KB image data can be stored in the memory block in the third row and third column. Since the memory capacity of a single memory block is 64KB, the 120KB image can occupy two memory blocks in the third row and third column, and the third row and fourth column; and the 128KB image data can be stored in two memory blocks in the fourth row and fourth column, and the fourth row and fifth column. It should be noted that when a single user stores data in the virtual memory, the data is stored sequentially, forming a continuous memory block in the data area, with no unstored memory blocks between the data. When multiple users store data in the virtual memory simultaneously, the data is stored synchronously and randomly, with unstored memory blocks between the data.

[0034] It should be noted that the first header area, when recording the offset and size of the allocated virtual memory for the four images, actually records the offset and capacity of the memory blocks occupied by the four images, rather than the actual size of the image data. The size of the allocated virtual memory for recording the four image data can be: 4 (64KB, 64KB, 128KB, 128KB); where 4 is the number of contiguous memory blocks occupied by the four image data, and the content in brackets is the capacity of the memory blocks occupied by the four image data respectively. The recording format shown in this application is only an example, and the specific recording process can also adopt other formats.

[0035] Image data needs to be formatted for easy storage when stored in the data area. The converted format mainly includes the following data: check data, total size of data items, save path, data length, save strategy, save mode, and data pointer. Among them, the check data is set to 16 bytes to verify data integrity; the total size of data items is set to 8 bytes to record the size of the entire data item. When allocating memory blocks for image data, the memory blocks are allocated based on the total size of the data items; the save path is set to 1000 bytes to record the data and name to be stored; the data length is set to 8 bytes and the data pointer is set to 8 bytes. The data length and data pointer work together to copy image data or other file data to the cache; the save strategy is set to 4 bytes to determine the save method, such as ordinary file reading and writing or IO data stream save method; the save mode is set to 4 bytes to determine the mode when data is saved, such as binary write, append write, or overwrite write save mode.

[0036] The data item queue manager is used to record the starting offset of the data and the total size of the data items, where the total size of the data items is the actual size of the data. Taking the example of storing 4 image data in the above-mentioned virtual memory, the element area records the above-mentioned 4 images in the form of a circular queue. Each row of the circular queue records the starting offset and actual memory occupied capacity of a data; for example, the first row of the circular queue records the starting offset of the first row and first column memory block, as well as the size of the image data 30KB.

[0037] The second header area is used to record characteristic information of the circular queue including: filling data, queue capacity, queue head index and queue tail index.

[0038] The above is the technical implementation method of the cache service component. In the logical implementation, the technical solution shown in this application is a typical producer / consumer model, in which producers are responsible for producing data and consumers are responsible for using data. Multiple producer threads will run at the same time, produce data, and put it into a shared area in the memory. The cache service component is actually this shared area and a set of interfaces for cache operations. Logically, the cache service component is mainly divided into cache Host and cache Agent. The cache Agent is further divided into producers (such as graphical intelligent software VISIONAssembly program) and consumers (file services). Producers and consumers will call the cache operation interface to complete the business layer processing, such as saving images, saving TXT and EXCEL files by appending or overwriting, etc. The cache service component shown in this application has the characteristics of portability, low coupling, compatibility with multiple file formats, easy-to-use interface and simple operation.

[0039] The above cache service component is configured with the shared memory management method shown below. By configuring this method in the cache service component, the allocation and release of the cache are realized.

[0040] Figure 2 A shared memory management method is shown in this application, and the method includes:

[0041] Step S101, obtaining virtual memory usage data; the virtual memory includes multiple memory blocks;

[0042] In some embodiments, through the member variable std::vector <gscapacitydata>m_vctElem records the current usage of virtual memory; to obtain the offset and size of the virtual memory allocated. When allocating virtual memory, an allocation algorithm (int Alloc_int64&nOffset, size_t nSize) is used.

[0043] Step S102, determining whether the virtual memory contains only one continuous memory block according to the virtual memory usage data;

[0044] In some embodiments, the occupied memory blocks in the virtual memory are traversed through m_vctElem to obtain the memory offset and the size of the memory capacity.

[0045] Step S103: If the number of occupied continuous memory blocks in the virtual memory is equal to 1, execute a cache allocation algorithm to store first data, where the first data may be a single data stored at the same time or a plurality of data stored at the same time.

[0046] In some embodiments, the virtual memory usage data includes: a total capacity of a memory block, a starting offset of the occupied memory block, and a memory capacity of the occupied memory block;

[0047] The executing a cache allocation algorithm to store the first data includes:

[0048] Obtaining the memory capacity of the unoccupied memory block according to the total capacity of the memory block, the starting offset of the occupied memory block, and the memory capacity of the occupied memory block;

[0049] Filtering unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data;

[0050] If the unoccupied memory blocks include unoccupied continuous memory blocks capable of storing the first data, storing the first data in the unoccupied continuous memory blocks;

[0051] If the unoccupied memory blocks do not include a continuous memory block capable of storing the first data, storing the first data in a memory block following the last continuous memory block in the occupied continuous memory blocks;

[0052] If there is overflow after storage, an error will be reported;

[0053] If there is no overflow after storage, the first data is returned to the starting offset.

[0054] In some embodiments, screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes:

[0055] When the number of occupied continuous memory blocks in the virtual memory is equal to 1, obtaining the memory capacity of the unoccupied continuous memory blocks;

[0056] If the memory capacity of the unoccupied continuous memory block is greater than or equal to the memory capacity of the first data, the first data is stored in the unoccupied continuous memory block.

[0057] In some embodiments, screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes:

[0058] When the number of occupied continuous memory blocks in the virtual memory is greater than 1, obtaining the memory capacity of the unoccupied continuous memory blocks;

[0059] If the memory capacity of the unoccupied continuous memory block is equal to the memory capacity of the first data, the first data is stored in an unoccupied continuous memory block with the same memory capacity as the first data, and the continuous memory block occupied by the first data is merged with the continuous memory blocks on both sides, and the number of continuous memory blocks in the virtual memory is updated. Figure 3 This example illustrates a situation where the memory capacity of the first data is equal to the unoccupied contiguous memory blocks. When multiple people store data simultaneously, the memory blocks in the data area are not stored contiguously, and unoccupied contiguous memory blocks exist between the data. In this case, a contiguous memory block with the same memory capacity as the first data is selected from the unoccupied contiguous memory blocks and the first data is stored in this contiguous memory block. At this point, the two original contiguous memory blocks are connected due to the storage of the first data, forming a new contiguous memory block. Therefore, the relevant information of the contiguous memory block on the right is deleted, and the number of contiguous memory blocks is updated.

[0060] In some embodiments, screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes:

[0061] When the number of occupied continuous memory blocks in the virtual memory is greater than 1, obtaining the memory capacity of the unoccupied continuous memory blocks;

[0062] If the memory capacity of the unoccupied continuous memory block is greater than the memory capacity of the first data, selecting an unoccupied continuous memory block having the smallest difference between the memory capacity of the unoccupied continuous memory block and the memory capacity of the first data;

[0063] The first data is stored in the selected unoccupied continuous memory block, and the continuous memory block occupied by the first data is merged with the continuous memory block adjacent to its left. Figure 4 This example illustrates a situation where the memory capacity of the first data is smaller than the number of unoccupied contiguous memory blocks. When multiple people are storing data simultaneously, the memory blocks in the data area are not stored contiguously, and unoccupied contiguous memory blocks may exist between the data. In this case, if there is no contiguous memory block with the same memory capacity as the first data among the occupied contiguous memory blocks, the contiguous memory block with the smallest difference in memory capacity with the first data is selected, the first data is stored in this contiguous memory block, and this block is merged with the leftmost block. In this case, the number of contiguous memory blocks in the data area remains unchanged.

[0064] In some embodiments, the method further comprises:

[0065] Step S201, obtaining a starting offset of the first data according to the virtual memory usage data;

[0066] Step S202: determine whether the sum of the data offset of the first data and the memory capacity of the first data is greater than the memory capacity allocated by the virtual memory.

[0067] Step S203: If the sum of the data offset of the first data and the memory capacity of the first data is greater than the memory capacity allocated by the virtual memory, an error is reported;

[0068] Step S204: If the sum of the data offset of the first data and the memory capacity of the first data is less than or equal to the memory capacity allocated by the virtual memory, obtain the starting offset of the first data to release the memory capacity of the first data.

[0069] In some embodiments, obtaining the starting offset of the first data to release memory capacity of the first data includes:

[0070] Traversing the occupied continuous memory blocks in the virtual memory to obtain the starting offset of the first data;

[0071] Figure 5 It shows a situation where the starting offset of the first data is located at the starting position of the memory block.

[0072] If the starting offset of the first data is at the starting position of any of the continuous memory blocks, and the memory capacity of the first data is equal to the memory capacity of the continuous memory block, deleting the continuous memory block to release the first data;

[0073] Figure 6 Another situation is shown in which the starting offset of the first data is located at the starting position of the memory block.

[0074] If the starting offset of the first data is at the starting position of any of the continuous memory blocks, and the memory capacity of the first data is smaller than the memory capacity of the continuous memory blocks, modifying the memory capacity of the last memory block of the continuous memory blocks to release the first data;

[0075] Figure 7 It shows a situation where the starting offset of the first data is located in the middle of the memory block.

[0076] If the starting offset of the first data is in the middle of any of the continuous memory blocks and the memory capacity of the first data is smaller than the memory capacity of the continuous memory block, splitting the continuous memory block and inserting a new continuous memory block to release the first data;

[0077] Figure 8 It shows a situation where the starting offset of the first data is located at the right side of the memory block.

[0078] If the starting offset of the first data is at the right position of any of the continuous memory blocks, and the memory capacity of the first memory block of the first data is smaller than the memory capacity of a single memory block, then the memory capacity of the single memory block occupied by the first memory block of the first data is modified to release the first data.

[0079] The technical solution shown above shows a shared memory management method and a cache service component. The cache service component shown in this application is essentially an asynchronous storage mechanism. The data to be saved is stored in the shared memory, and then the file system takes out the data from the shared memory for saving, so as to separate the data saving function from the graphical intelligent vision software, and can operate the external interface frequently without affecting the graphical intelligent vision software.

[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some or all of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

[0081] For ease of explanation, the above description has been made with reference to specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations are possible. The above embodiments are selected and described to better explain the principles and practical applications, so that those skilled in the art can better utilize the embodiments and various different variations of the embodiments suitable for specific use considerations.< / gscapacitydata>

Claims

1. A shared memory management method, characterized in that: The method comprises: Acquiring virtual memory usage data; the virtual memory includes multiple memory blocks; determining, based on the virtual memory usage data, whether the virtual memory includes only one continuous memory block; If the number of occupied continuous memory blocks in the virtual memory is equal to 1, executing a cache allocation algorithm to store first data, where the first data is a single data stored at the same time, or a plurality of data stored at the same time; The virtual memory usage data includes: the total capacity of the memory block, the starting offset of the occupied memory block and the memory capacity of the occupied memory block; The executing a cache allocation algorithm to store the first data includes: Obtaining the memory capacity of the unoccupied memory block according to the total capacity of the memory block, the starting offset of the occupied memory block, and the memory capacity of the occupied memory block; Filtering unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data; If the unoccupied memory blocks include unoccupied continuous memory blocks capable of storing the first data, storing the first data in the unoccupied continuous memory blocks; If the unoccupied memory blocks do not include a continuous memory block capable of storing the first data, storing the first data in a memory block following the last continuous memory block in the occupied continuous memory blocks; If there is overflow after storage, an error will be reported; If there is no overflow after storage, returning the first data to the starting offset; The method further comprises: Obtaining a starting offset of the first data according to the virtual memory usage data; Determine whether the sum of the data offset of the first data and the memory capacity of the first data is greater than the memory capacity allocated by the virtual memory, If the sum of the data offset of the first data and the memory capacity of the first data is greater than the memory capacity allocated by the virtual memory, an error processing is performed; If the sum of the data offset of the first data and the memory capacity of the first data is less than or equal to the memory capacity allocated by the virtual memory, obtaining the starting offset of the first data to release the memory capacity of the first data; The obtaining the starting offset of the first data to release memory capacity of the first data includes: Traversing the occupied continuous memory blocks in the virtual memory to obtain the starting offset of the first data; If the starting offset of the first data is at the starting position of any of the continuous memory blocks, and the memory capacity of the first data is equal to the memory capacity of the continuous memory block, deleting the continuous memory block to release the first data; If the starting offset of the first data is at the starting position of any of the continuous memory blocks, and the memory capacity of the first data is smaller than the memory capacity of the continuous memory blocks, modifying the memory capacity of the last memory block of the continuous memory blocks to release the first data; If the starting offset of the first data is in the middle of any of the continuous memory blocks and the memory capacity of the first data is smaller than the memory capacity of the continuous memory block, splitting the continuous memory block and inserting a new continuous memory block to release the first data; If the starting offset of the first data is at the right position of any of the continuous memory blocks, and the memory capacity of the first memory block of the first data is smaller than the memory capacity of a single memory block, then the memory capacity of the single memory block occupied by the first memory block of the first data is modified to release the first data.

2. The shared memory management method according to claim 1, wherein: The step of screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes: When the number of occupied continuous memory blocks in the virtual memory is equal to 1, obtaining the memory capacity of the unoccupied continuous memory blocks; If the memory capacity of the unoccupied continuous memory block is greater than or equal to the memory capacity of the first data, the first data is stored in the unoccupied continuous memory block.

3. The shared memory management method according to claim 1, wherein: The step of screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes: When the number of occupied continuous memory blocks in the virtual memory is greater than 1, obtaining the memory capacity of the unoccupied continuous memory blocks; If the memory capacity of the unoccupied continuous memory block is equal to the memory capacity of the first data, the first data is stored in an unoccupied continuous memory block with the same memory capacity as the first data, and the continuous memory block occupied by the first data is merged with the continuous memory blocks on both sides, and the number of continuous memory blocks in the virtual memory is updated.

4. The shared memory management method according to claim 1, wherein: The step of screening unoccupied continuous memory blocks from the unoccupied memory blocks to store the first data includes: When the number of occupied continuous memory blocks in the virtual memory is greater than 1, obtaining the memory capacity of the unoccupied continuous memory blocks; If the memory capacity of the unoccupied continuous memory block is greater than the memory capacity of the first data, selecting an unoccupied continuous memory block having the smallest difference between the memory capacity of the unoccupied continuous memory block and the memory capacity of the first data; The first data is stored in the selected unoccupied continuous memory block, and the continuous memory block occupied by the first data is merged with the continuous memory block adjacent to the left thereof.

5. A cache service component, characterized in that: Used to execute the shared memory management method according to any one of claims 1 to 4, the cache service component includes: a cache allocator and a data item queue manager; The cache allocator is used for allocating and releasing virtual memory; the data item queue manager is used for recording the location of the data in the cache allocator in the virtual memory and the total size of the data items; The cache allocator includes: a first header area and a data area, wherein the first header area is connected to the data area, the first header area is used to record the offset and size of the allocated virtual memory, the data area includes a plurality of equally divided memory blocks, and the memory blocks are used to record the data placed in the virtual memory; The data item queue manager includes: a second header area and an element area, the second header area is connected to the element area, the element area includes a circular queue, the circular queue is used to record the starting offset of the data and the total size of the data item, and the second header area is used to record the characteristic information of the circular queue.

6. The cache service component according to claim 5, characterized in that: The capacity of each memory block is 64KB.

Citation Information

Patent Citations

  • Method for allocating shared memory

    CN103440203A

  • Cache sharing method and device and electronic equipment

    CN113176942A