Data storage method and device and electronic equipment
By introducing memory pools and object pools into computing devices, managing data storage in ring queues, memory management problems caused by frequent data storage and destruction are solved, and performance and memory utilization are improved.
Patent Information
- Application Number
- CN202411956807.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-29
AI Technical Summary
When using ring queues for data storage, frequent data storage and destructuring operations lead to too frequent dynamic allocation and release of system memory, which increases the burden of memory management, affects the performance of computing devices, and leads to memory fragmentation, reducing memory utilization.
By introducing a memory pool and an object pool in the computing device, the target data is stored in the memory pool in response to a data storage request, and the target object is determined based on the storage information, and then the target memory block is determined in the object pool, and the target object is stored in the memory block.
This method avoids frequent application of heap memory to system memory dynamically, reduces the burden of system memory management, improves the performance of computing devices, reduces memory fragmentation, improves the utilization and stability of system memory, and improves the response speed of storage.
Smart Images

Figure CN119902737A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to data storage technology, and in particular to a data storage method, device and electronic device. Background Art
[0002] Ring queues are widely used in real-time scheduling scenarios of information in chip test equipment because of their loop structure that efficiently supports the FIFO (First In First Out) principle. When using a ring queue, dynamic memory is usually used to store data in the ring queue.
[0003] In the process of implementing the present application, it was found through research that each data storage and data destruction operation requires dynamic allocation and release of system memory. However, the data in the circular queue is often accompanied by frequent data storage and data destruction operations, which requires frequent dynamic application of heap memory to the system memory. This not only increases the burden of memory management and affects the performance of the computing device, but also because the system memory is frequently allocated and released, it also leads to a large amount of memory fragmentation, resulting in low memory utilization. Summary of the invention
[0004] In order to solve the above technical problems, the embodiments of the present application provide a data storage method, device and electronic device.
[0005] One aspect of an embodiment of the present application provides a data storage method, which is applied to a computing device, wherein the computing device includes a memory pool and an object pool, and the method includes: in response to receiving a storage request for target data, storing the target data in the memory pool, and determining a first target object corresponding to the target data based on storage information of the target data in the memory pool; determining a target memory block from multiple memory blocks in the object pool based on a target storage position of the first target object in a circular queue; and storing the first target object in the target memory block.
[0006] Another aspect of an embodiment of the present application provides a data storage device, which is applied to a computing device, wherein the computing device includes a memory pool and an object pool, and the device includes: an object construction module, which is used to store the target data in the memory pool in response to receiving a storage request for target data, and determine a first target object corresponding to the target data based on storage information of the target data in the memory pool; a first memory block determination module, which is used to determine a target memory block from multiple memory blocks in the object pool based on a target storage position of the first target object in a circular queue; and a first storage module, which is used to store the first target object in the target memory block.
[0007] Another aspect of an embodiment of the present application provides an electronic device, comprising: a memory for storing a computer program; a processor for executing the computer program stored in the memory, and when the computer program is executed, the above-mentioned data storage method is implemented.
[0008] In another aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored, characterized in that when the computer program is executed by a processor, the above-mentioned data storage method is implemented.
[0009] In another aspect of the embodiments of the present application, a computer program product is provided, including computer program instructions, characterized in that the computer program instructions implement the above-mentioned data storage method when executed by a processor.
[0010] Data storage method, device, electronic device, storage medium and program product in the embodiments of the present application. In response to receiving a storage request for target data, based on the storage information of the target data in the memory pool, determine the target object corresponding to the target data, then determine the target memory block in multiple memory blocks in the object pool based on the target storage position of the target object in the circular queue, store the target object in the target memory block, so that the target data is added to the circular queue. In the application embodiment, the object pool and the memory pool are used to store the first target object and the target data respectively to centrally manage the first target object and the target data, thereby avoiding frequent dynamic application of heap memory to the system memory, thereby not only reducing the management burden of the system memory, ensuring the performance of the computing device, but also reducing the situation of memory fragmentation, improving the utilization and stability of the system memory, and improving the response speed of storage.
[0011] The technical solution of the present application is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present application and, together with the description, serve to explain the principles of the present application.
[0013] The present application can be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:
[0014] Figure 1 is a flowchart of a data storage method provided by an exemplary embodiment of the present application;
[0015] Figure 2 is a schematic diagram of a target object and target data storage provided by an exemplary embodiment of the present application;
[0016] Figure 3 is a flowchart of step S110 provided by an exemplary embodiment of the present application;
[0017] Figure 4 is a schematic diagram of an object pool provided by an exemplary embodiment of the present application;
[0018] Figure 5 is a flow chart of a data storage method provided by another exemplary embodiment of the present application;
[0019] Figure 6 is a schematic diagram of a storage method provided by an exemplary embodiment of the present application;
[0020] Figure 7 is a flowchart of a data storage method provided by another exemplary embodiment of the present application;
[0021] Figure 8 is a flowchart of a data storage method provided by another exemplary embodiment of the present application;
[0022] Fig. 9 is a schematic diagram of multi-level memory allocation provided by an exemplary embodiment of the present application;
[0023] Fig.10 is a structural block diagram of a data storage device provided by an exemplary embodiment of the present disclosure;
[0024] Fig.11 This is a schematic diagram of the structure of an application embodiment of the electronic device of the present application. DETAILED DESCRIPTION
[0025] Various exemplary embodiments of the present application will now be described in detail with reference to the accompanying drawings. It should be noted that unless otherwise specifically stated, the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present application.
[0026] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present application are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.
[0027] It should also be understood that in the embodiments of the present application, "plurality" may refer to two or more than two, and "at least one" may refer to one, two or more than two.
[0028] It should also be understood that any component, data or structure mentioned in the embodiments of the present application can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0029] In addition, the term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.
[0030] It should also be understood that the description of the various embodiments in this application focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.
[0031] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0032] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present application, its application, or uses.
[0033] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0034] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0035] The embodiments of the present application can be applied to electronic devices such as terminal devices, computer systems, servers, etc., which can operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, servers, etc. include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.
[0036] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment, where tasks are performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.
[0037] In the process of implementing the present application, it was found through research that since non-POD (Plain Old Data) type data usually includes complex data structures, dynamic memory, smart pointers or other resource management mechanisms, each data storage and data destruction of non-POD type data requires dynamic allocation and release of system memory. This requires frequent dynamic application of heap memory to the system memory when the computing device is in high concurrency and requires frequent data storage and data destruction. This not only increases the memory management burden, but also causes a large amount of memory fragmentation in the system memory, resulting in low memory utilization.
[0038] Figure 1 is a flow chart of a data storage method provided by an exemplary embodiment of the present application. This embodiment can be applied to a computing device, such as Figure 1 As shown, the data storage method may include the following steps:
[0039] Step S100 , in response to receiving a storage request for target data, storing the target data in a memory pool, and determining a first target object corresponding to the target data based on storage information of the target data in the memory pool.
[0040] Among them, the computing device can be, for example, a chip testing device or an embedded processing device. The chip testing device is used to test the function and / or performance of a chip, a wafer or an integrated circuit. For example, the chip testing device can be an integrated circuit automatic tester (Automatic Test Equipment, ATE). The chip testing device includes a host computer and a slave computer. The host computer can be a computing device, which is used to control the slave computer to test the chip, wafer or integrated circuit to be tested, and store and display the test results, etc. The computing device can include, for example, a desktop computer, a tablet computer, a laptop computer, a server or a smart phone, etc. The slave computer can be used to test the chip, wafer or integrated circuit to be tested, for example, the slave computer can include a test head, etc.
[0041] The computing device may include a memory pool and an object pool. The memory pool is used to store data, and the object pool is used to store data objects. In one embodiment, when the computing device is a chip testing device, the memory pool and the object pool may be set in a host computer, and the memory pool and the object pool may be pre-divided in the system memory of the host computer, and the memory pool and the object pool respectively include a storage space of a certain size.
[0042] The data object can be used to represent the relevant information of the data. The data object may include, for example: the identification, storage address, size and timestamp of the data, and the identification of the object, etc. The first target object may include the storage information of the target data, and the storage information includes the starting storage address and the ending storage address of the target data in the memory pool.
[0043] In one embodiment, when the host computer receives a storage request, it can use a preset first space configurator for managing memory pools and object pools to allocate storage space to the target data in the memory pool to determine the storage information of the target data in the memory pool, and store the target data in the memory pool based on the storage information, and create a first target object based on the storage information of the target data.
[0044] Step S110 , determining a target memory block from a plurality of memory blocks in the object pool based on a target storage position of the first target object in the circular queue.
[0045] The object pool includes memory blocks, each of which has a storage space of a certain size, and the memory blocks are used to store data objects.
[0046] A circular queue is a data structure that can be used to store and manage data. In an embodiment of the present application, the circular queue is used to store data objects, and the circular queue includes multiple storage locations, each of which is used to store an object.
[0047] In one embodiment, after receiving a storage request, a tail pointer (rear) in the circular queue is determined, and the storage location where the tail pointer is located is determined as the target storage location of the first target object in the circular queue, and the first target object is written into the circular queue to enqueue (push) the first target object. The first space configurator can determine the memory block corresponding to the target storage location based on the mapping relationship between the preset storage location and the memory block, and determine the memory block as the target memory block, and allocate the target memory block to the first target object.
[0048] Step S120: store the first target object in the target memory block.
[0049] The first target object may be stored in the target memory block to complete the addition of the target data into the ring queue.
[0050] In the application embodiment, an object pool and a memory pool are used to store the first target object and the target data respectively so as to centrally manage the first target object and the target data, thereby avoiding frequent dynamic requests for heap memory from the system memory. This not only reduces the management burden of the system memory and ensures the performance of the computing device, but also reduces memory fragmentation, improves the utilization and stability of the system memory, and improves the response speed of the storage.
[0051] Figure 2 FIG. 1 is a schematic diagram of a target object and target data storage provided by an exemplary embodiment of the present application. Figure 2 As shown, assuming that the first target object corresponding to the target data is 8', the first space allocator stores the target data in the data area of the memory pool. Figure 2 A memory segment is shown in the figure, which includes 12 memory blocks. Memory block 1 represents the head of the memory segment. Assuming that the memory block pointed to by the first target object 8′ is the tail of the memory segment, which is the determined target memory block, the first target object 8′ is transferred (stored) to the target memory block to obtain memory block 8, so as to store the first target object 8′ in the target memory block.
[0052] In some optional implementations, the object pool in the embodiment of the present application includes a plurality of consecutive index nodes and a plurality of memory segments, each memory segment includes a plurality of memory blocks, wherein the plurality of memory segments can be linked in the form of a linked list.
[0053] Figure 3 is a flow chart of step S110 provided by an exemplary embodiment of the present application. In some optional implementations, such as Figure 3 As shown, step S110 may include the following steps:
[0054] Step S111 : determining a target index node corresponding to a target storage position of a first target object in a circular queue from among a plurality of index nodes based on a mapping relationship between preset index nodes and storage positions.
[0055] Among them, the mapping relationship between the preset index node and the storage location can be understood as the mapping relationship between the preset index node and the storage location, and the mapping relationship between the preset index node and the storage location may include: the mapping relationship between each index node and the storage location in the circular queue, that is, each index node is mapped to a storage location in the circular queue.
[0056] In one implementation, based on a mapping relationship between a preset index node and a storage location, an index node corresponding to the target storage location may be determined from a plurality of index nodes, and the index node may be determined as the target index node.
[0057] Step S112: based on the mapping relationship between the preset index nodes and the memory segments, determine the target memory segment corresponding to the target index node in the multiple memory segments.
[0058] Among them, the mapping relationship between the preset index nodes and the memory segments can be understood as the mapping relationship between the preset index nodes and the memory segments, and the mapping relationship between the preset index nodes and the memory segments includes: the mapping relationship between each index node and the memory segment, that is, each index node is mapped to a memory segment.
[0059] In one implementation, based on a mapping relationship between a preset index node and a memory segment, a memory segment corresponding to the target index node may be determined from multiple memory segments, and the memory segment may be determined as the target memory segment.
[0060] Step S113, determining a target memory block based on the current memory block in the target memory segment.
[0061] The current memory block is the memory block of the latest storage object in the target memory segment. In one embodiment, each memory block includes a pointer, which is used to point to the address of the next memory block of the memory block. The next memory block of the current memory block can be determined based on the pointer in the current memory block, and the next memory block is determined as the target memory block.
[0062] For example, Figure 4 FIG. 1 is a schematic diagram of an object pool provided by an exemplary embodiment of the present application. Figure 4 As shown, the object pool includes 4 object segments (corresponding to memory segments) and an object segment manager. The object segment manager includes 4 continuous index nodes, which are segment 1 to segment 4. Start indicates the starting point of the continuous index node, and End indicates the end point of the continuous index node. The 4 object segments are object segment 1 to object segment 4. Each index node is mapped to a memory segment, that is, segment 1 is mapped to object segment 1, segment 2 is mapped to object segment 2, segment 3 is mapped to object segment 3, and segment 4 is mapped to object segment 4. Figure 4 The white memory blocks in the middle represent free memory blocks, that is, unallocated (stored) objects, and the gray memory blocks represent memory blocks with allocated (stored) objects. The first digits of the four object segments are connected to form a circular storage area. Each object segment includes 8 memory blocks, and each memory block can store an object. For example, object 1 can be stored in memory block 1. Among them, memory blocks 6-22 represent memory blocks with stored objects.
[0063] In the embodiment of the present application, the mapping relationship between the preset index node and the storage location, and the mapping relationship between the preset index node and the memory segment are utilized to accurately and efficiently determine the target memory block.
[0064] In some optional embodiments, before step S100 in the embodiment of the present application, the step includes: in response to the data type of the target data being a first preset data type, executing an operation in response to receiving a storage request for the target data, storing the target data in a memory pool, and determining, based on the storage information of the target data in the memory pool, an operation of a first target object corresponding to the target data.
[0065] Among them, the first preset data type is a non-POD type. In one embodiment, a templated interface for determining the data type can be pre-set, and the type of the target data is extracted through the templated interface, and the data type of the target data is determined according to the return value in the type extraction result. The templated interface can support perfect forwarding (PerfectForwarding) to achieve transparent transmission of the data type.
[0066] Alternatively, the data type of the target data can also be determined by judging whether the target data includes a pointer for indicating a storage address. When the target data includes a pointer for indicating a storage address, the data type of the target data can be determined to be a first preset data type. When the target data does not include a pointer for indicating a storage address, the data type of the target data can be determined to be a second preset data type.
[0067] When it is determined that the data type of the target data is a non-POD type (a first preset data type), steps S100 to S120 are executed.
[0068] Figure 5 FIG. 1 is a flow chart of a data storage method provided by another exemplary embodiment of the present application. In some optional implementations, such as Figure 5 As shown, before step S100, the following steps are also included:
[0069] Step S210 , in response to the data type of the target object being a second preset data type, determining a second target object corresponding to the target data based on data information of the target data.
[0070] The second preset data type is a POD type. The data information of the target data may include, for example, an identifier, a size, a name, etc. of the target data. The second target object may include the data information of the target data, etc.
[0071] Step S220: determining a target memory block based on a target storage position of the second target object in the circular queue.
[0072] Among them, the method of determining the target memory block based on the target storage position of the second target object in the circular queue can refer to the method of determining the target memory block based on the target storage position of the first target object in the circular queue, which will not be repeated here.
[0073] Step S230: store the target data and the second target object in the target memory block.
[0074] In one implementation, the second target object and the target data may be stored in the target storage block using a transfer method of copy semantics.
[0075] In the application embodiment, the best storage method is automatically selected for the target data according to the data type of the target data, thereby improving the data storage efficiency and the performance of the circular queue.
[0076] In some optional embodiments, in an embodiment of the present application, after determining that the data type of the target data is the first preset data type, it may also include: in response to the storage form included in the storage request being queue storage, or the storage form being empty, executing in response to receiving a storage request for the target data, storing the target data in a memory pool, and determining an operation of a first target object corresponding to the target data based on storage information of the target data in the memory pool; in response to the storage form included in the storage request being default storage, storing the target data in the system memory of the computing device.
[0077] The first preset data type may also be a user-defined data type. In one embodiment, when the data type is determined to be the first preset data type, the storage form in the storage request is determined, and when the storage form in the storage request is determined to be queue storage, steps S100 to S120 may be executed, or when the storage form in the storage request is determined to be empty, steps S100 to S120 may be executed;
[0078] When the storage form in the storage request is default storage, storage space can be applied to the system memory, and the target data can be stored in the storage space using copy semantics. When the target data is stored in the default storage mode, the target data is not written to the ring queue.
[0079] For example, Figure 6 It is a schematic diagram of a storage method provided by an exemplary embodiment of the present application. As shown in 6, a second space configurator for system memory management can be pre-set. When it is determined that the data type of the target data is a user-defined data type (first preset data type) and the storage form included in the storage request is queue storage, the first space configurator is used to perform steps S110 to S120. When it is determined that the data type of the target data is a user-defined data type and the storage form included in the storage request is default storage, the second space configurator is used to allocate storage space to the target data in the system memory to store the target data in the system memory.
[0080] In the embodiment of the present application, different storage forms can be selected to store the target data according to the needs of the user, thereby improving the flexibility of data storage and increasing the efficiency of data storage.
[0081] In some optional embodiments, step S120 in the embodiment of the present application may include: in response to the data type of the target data being a first preset data type, storing the first target object in the target memory block using move semantics; in response to the data type of the target data being a second preset data type, storing the target data and the second target object in the target memory block using copy semantics.
[0082] In one embodiment, when the data type of the target data is a first preset data type, the first target object can be stored in the target memory block based on perfect forwarding and using a transfer method of move semantics. Exemplarily, the name, identifier, size of the target data in the first target object, and the identifier of the first target object can be stored in the target memory block by bit-copying, and the ownership of the resource pointed to by the first target object (storage information of the target data) can be transferred to the target memory block in a move semantic manner.
[0083] When the data type of the target data is the second preset data type, the second target object and the target data may be stored in the target storage block based on perfect forwarding and using a transfer method of copy semantics.
[0084] In an embodiment of the present application, the optimal transfer method (copy semantics or move semantics) is automatically selected according to the data type of the target data, ensuring the high efficiency of system operation, while reducing unnecessary resource consumption, further improving the execution efficiency of the circular queue, and when the data type is the first preset data type, the first target object is stored in the target memory block using move semantics, further reducing memory fragmentation.
[0085] Figure 7 FIG. 1 is a flow chart of a data storage method provided by another exemplary embodiment of the present application. In some optional implementations, such as Figure 7 As shown, the data storage method also includes the following steps:
[0086] Step S300 , in response to receiving a request to remove target data of a first preset data type, determining a target memory block based on a target storage position of a first target object in a ring queue.
[0087] In one embodiment, the first target object further includes a data type of the target data and an identifier of the first target object.
[0088] When it is determined that the data type of the target data corresponding to the first target object is the first preset data type, the index node corresponding to the target storage position of the first target object in the circular queue can be determined from multiple index nodes based on the mapping relationship between the preset index node and the target storage position, and the index node can be determined as the target index node. Thereafter, based on the mapping relationship between the preset index node and the memory segment, the memory segment corresponding to the target index node can be determined from multiple memory segments, and the memory segment can be determined as the target memory segment. Based on the identifier of the first target object, the target memory block for storing the first target object can be determined in the target memory segment.
[0089] Step S310, removing the first target object from the target memory block.
[0090] The first space allocator may be used to move the first target object out of the target memory block to release storage space in the target memory block, so as to pop the first target object out of the queue.
[0091] In an embodiment of the present application, the first target object in the target memory block is moved out to release the object pool storage space, so that the object pool storage space can be reused, thereby improving the utilization rate of storage resources. At the same time, it also avoids frequent application and release of memory from the system memory in high concurrency scenarios, further improving the efficiency of data storage.
[0092] In some optional embodiments, the data storage method in the embodiments of the present application may also include: in response to receiving a removal request for target data whose data type is a second preset data type, determining a target memory block based on the target storage position of the second target object in the circular queue, and then deleting the target data and the second target object in the target memory block.
[0093] The second target object may also include an identifier of the second target object. The method of determining the target memory block based on the target storage position of the second target object in the circular queue is the same as the method of determining the target memory block based on the target storage position of the first target object in the circular queue, which will not be repeated here.
[0094] In the application embodiment, the storage space of the object pool is released by deleting the second target object and the target data in the target memory block, so that the storage space of the object pool can be reused, thereby improving the utilization rate of storage resources.
[0095] Figure 8 FIG. 1 is a flow chart of a data storage method provided by another exemplary embodiment of the present application. In some optional implementations, such as Figure 8 As shown, the data storage method also includes the following steps:
[0096] Step S400 , in response to the size of the available storage space in the object pool being smaller than a first preset threshold, sending a memory segment application request to the memory pool.
[0097] The first preset threshold may be used to represent a threshold of a preset storage space size. The first preset threshold may be, for example, the size of the storage space corresponding to the two memory segments.
[0098] In one embodiment, the size of the available storage space in the object pool can be monitored in real time. When the object pool is about to be exhausted, that is, the size of the available storage space in the object pool is less than a first preset threshold, the first space configurator sends a memory segment application request to the memory pool, and the memory segment application request includes the number of memory segments to be applied for.
[0099] Step S410, in response to the size of the comprehensive spare storage space corresponding to the spare memory segment in the memory pool being greater than or equal to the second preset threshold, a new memory segment is obtained from the spare memory segment and allocated to the object pool.
[0100] The memory pool includes a plurality of spare memory segments, and the size of the comprehensive spare storage space is used to represent the sum of the sizes of the storage spaces of the spare memory segments. The second preset threshold value can be used to represent the threshold value of the preset storage space size.
[0101] In one embodiment, when the size of the comprehensive spare storage space is greater than or equal to the second preset threshold, the first space manager may obtain spare memory segments of the number of memory segments required in the memory segment application request from the spare memory segments and allocate them as new memory segments to the object pool.
[0102] After the object pool is allocated a new memory segment, a new index node corresponding to the new memory segment is created, and the new index node can be set at the end of the existing multiple consecutive index nodes. The circular queue is expanded to add a new storage location, and a mapping relationship between the new storage location and the new index node is established, and a mapping relationship between the new index node and the new memory segment is suggested.
[0103] Step S420 , in response to the size of the comprehensive spare storage space being smaller than a second preset threshold, allocating a new memory segment from the system memory to the object pool.
[0104] In the embodiment of the present application, there is no execution order between step S410 and step S420.
[0105] In an embodiment of the present application, a spare memory segment can be set in the memory pool to supplement the object pool, which not only improves the data storage efficiency but also avoids the object pool frequently requesting memory from the system memory when high-frequency operations are performed to access data, thereby improving the stability of the system.
[0106] In some optional embodiments, the data storage method in the embodiments of the present application also includes: in response to the size of the available storage space in the object pool being greater than a first preset threshold for a duration exceeding a preset duration, determining the size of the first returned storage space based on the size of the available storage space in the object pool and the first preset threshold, and then returning the memory segments of non-stored objects corresponding to the size of the first returned storage space in the object pool to the memory pool.
[0107] The preset duration can be set according to the requirements, for example, the preset duration can be 10 minutes, etc. In one embodiment, the difference between the value of the size of the available storage space of the object pool and the first preset threshold value can be determined as the value of the size of the first returned storage space. The memory segment returned to the memory pool can be determined as the spare memory segment.
[0108] The size of the first returned storage space can be determined by the first space configurator, and the number of returned memory segments can be determined based on the size of the first returned storage space and the size of the storage space corresponding to each memory segment. The first space manager allocates the number of memory segments of non-stored objects to the memory pool to return the memory segments of non-stored objects corresponding to the size of the first returned storage space to the memory pool.
[0109] In one implementation, the index node corresponding to the memory segment returned to the memory pool may be deleted, and the storage location corresponding to the index node may be deleted from the circular queue.
[0110] In the embodiment of the present application, by returning the redundant memory segments that have not been used for a long time in the object pool to the memory pool, the memory segments are prevented from being idle for a long time, thereby improving the utilization rate of the memory segments.
[0111] In some optional embodiments, the data storage method in the embodiment of the present application also includes: in response to the size of the available storage space in the memory pool being less than a preset third preset threshold, obtaining supplementary memory from the system memory to allocate the supplementary memory to the memory pool.
[0112] The third preset threshold may be used to represent a threshold of a preset storage space size.
[0113] In some optional implementations, when the memory pool is about to be exhausted, that is, when the size of the available storage space in the memory pool is less than a preset third preset threshold, the first space allocator applies to the system of the upper computer for additional memory, and the memory pool is supplemented by the additional memory. When the system memory application fails, an attempt is made to make the system reclaim part of the memory and then retry. After the retry fails, a bad_alloc exception is thrown. Among them, the difference between the size of the available storage space in the memory pool and the preset third preset threshold can be determined as the size corresponding to the additional memory.
[0114] In some optional embodiments, the data storage method in the embodiments of the present application also includes: in response to the size of the available storage space in the memory pool being greater than a preset third preset threshold for a duration exceeding a preset duration, determining the size of the second returned storage space based on the size of the available storage space in the memory pool and the third preset threshold, and then returning the memory in the memory pool that does not store data corresponding to the size of the second returned storage space to the system memory.
[0115] The difference between the size of the available storage space of the memory pool and the third preset threshold may be determined as the value of the size of the second returned storage space.
[0116] In an embodiment of the present application, by monitoring the size of the available storage space in the memory pool, it is possible to instantly replenish memory or release memory (return system memory) to the memory pool, thereby ensuring that there is sufficient storage space in the memory pool to store data. At the same time, it also avoids the memory pool having excess memory that is idle for a long time, thereby improving memory utilization.
[0117] For example, Fig. 9 FIG. 1 is a schematic diagram of multi-level memory allocation provided by an exemplary embodiment of the present application. Fig. 9 As shown, the system memory can be initially allocated to the corresponding memory of the memory pool. The memory in the memory pool can exist in the form of memory pool segments. Fig. 9 In the example, the memory pool includes N memory pool segments, each memory pool segment has a certain size of storage space, and the first space configuration performs secondary allocation on the memory pool, that is, a memory pool segment for storing objects is determined in the N memory pool segments and allocated to the object pool as an object segment (memory segment). Fig. 9 There are n object segments in the memory pool, each object segment is mapped to an index node in the object segment manager, N and n are both integers greater than or equal to 1, and N>n. In addition, the first space allocator can also allocate a certain number of memory pool segments in the N memory pool segments as spare memory segments.
[0118] Fig.10 : is a structural block diagram of a data storage device provided by an exemplary embodiment of the present disclosure. The data storage device is applied to a computing device, and the computing device includes a memory pool and an object pool. The data storage device includes:
[0119] The object construction module 500 is used to store the target data in the memory pool in response to receiving a storage request for the target data, and determine a first target object corresponding to the target data based on storage information of the target data in the memory pool;
[0120] A first memory block determination module 510, configured to determine a target memory block from among a plurality of memory blocks in the object pool based on a target storage position of the first target object in the circular queue;
[0121] The first storage module 520 is configured to store the first target object in the target memory block.
[0122] In some optional implementations, the object pool includes a plurality of consecutive index nodes and a plurality of memory segments, and each memory segment includes a plurality of memory blocks;
[0123] The determining of a target memory block from a plurality of memory blocks in the object pool based on the target storage position of the first target object in the circular queue is further used for:
[0124] Based on a mapping relationship between preset index nodes and storage locations, determining a target index node corresponding to a target storage location of the first target object in the ring queue from among the multiple index nodes;
[0125] Based on a mapping relationship between preset index nodes and memory segments, determining a target memory segment corresponding to the target index node from among the multiple memory segments;
[0126] The target memory block is determined based on a current memory block in the target memory segment, where the current memory block is a memory block that stores the latest object in the target memory segment.
[0127] In some optional implementations, the data storage device further includes:
[0128] a first type determination module, configured to, in response to a data type of the target data being a first preset data type, execute, in response to receiving a storage request for the target data, an operation of storing the target data in the memory pool and determining, based on storage information of the target data in the memory pool, a first target object corresponding to the target data;
[0129] A second type determination module, configured to determine, in response to the data type of the target object being a second preset data type, a second target object corresponding to the target data based on data information of the target data;
[0130] A second storage determination module, configured to determine the target memory block based on a target storage position of the second target object in the circular queue;
[0131] The second storage module is used to store the target data and the second target object in the target memory block.
[0132] In some optional implementations, the data storage device further includes:
[0133] The first type determination module is further configured to, in response to the storage form included in the storage request being queue storage or the storage form being empty, execute, in response to receiving a storage request for target data, storing the target data in the memory pool, and determining, based on storage information of the target data in the memory pool, an operation of a first target object corresponding to the target data;
[0134] The second type determination module is further configured to store the target data in the system memory of the computing device in response to the storage form included in the storage request being default storage.
[0135] In some optional implementations, storing the target object in the target memory block is further performed:
[0136] In response to the data type of the target data being the first preset data type, storing the first target object in the target memory block by using move semantics;
[0137] In response to the data type of the target data being the second preset data type, the target data and the second target object are stored in the target memory block by using copy semantics.
[0138] In some optional implementations, the data storage device further includes:
[0139] The first dequeue module is used to respond to receiving a removal request for target data of a first preset data type, determine the target memory block based on the target storage position of the first target object in the circular queue, and remove the first target object from the target memory block.
[0140] In some optional implementations, the data storage device further includes:
[0141] A second dequeue module is used to respond to receiving a removal request for target data of a second preset data type, determine the target memory block based on the target storage position of the second target object in the circular queue; and delete the target data and the second target object in the target memory block.
[0142] In some optional implementations, the data storage device further includes:
[0143] The first object pool management module is used to send a memory segment application request to the memory pool in response to the size of the available storage space in the object pool being less than a first preset threshold; to obtain a new memory segment from the spare memory segment and allocate it to the object pool in response to the size of the comprehensive spare storage space corresponding to the spare memory segment in the memory pool being greater than or equal to a second preset threshold; and to allocate the new memory segment to the object pool from the system memory in response to the size of the comprehensive spare storage space being less than the second preset threshold.
[0144] In some optional implementations, the data storage device further includes:
[0145] A second object pool management module is used to determine the size of a first returned storage space based on the size of the available storage space in the object pool and the first preset threshold in response to the size of the available storage space in the object pool being greater than the first preset threshold for a duration exceeding a preset time; and return the memory segments of non-stored objects corresponding to the size of the first returned storage space in the object pool to the memory pool.
[0146] In some optional implementations, the data storage device further includes:
[0147] A memory pool management module is used for, in response to the size of the available storage space in the memory pool being less than a preset third preset threshold, obtaining supplementary memory from the system memory to allocate the supplementary memory to the memory pool; in response to the size of the available storage space in the memory pool being greater than the preset third preset threshold for a duration exceeding a preset duration, determining the size of a second returned storage space based on the size of the available storage space in the memory pool and the third preset threshold; and returning the memory in the memory pool that does not store data and corresponds to the size of the second returned storage space to the system memory.
[0148] The data storage device of the embodiment of the present disclosure corresponds to the embodiment of the data storage method of the present disclosure, and the relevant contents can be referenced to each other and will not be repeated here.
[0149] The beneficial technical effects corresponding to the exemplary embodiments of the data storage device of the disclosed embodiments can be found in the corresponding beneficial technical effects of the above-mentioned corresponding exemplary method part, which will not be repeated here.
[0150] In addition, an embodiment of the present disclosure further provides an electronic device, including:
[0151] Memory for storing computer programs;
[0152] The processor is used to execute the computer program stored in the memory, and when the computer program is executed, the data storage method described in any of the above embodiments of the present disclosure is implemented.
[0153] Fig.11 This is a schematic diagram of the structure of an application embodiment of the electronic device disclosed in the present invention. Fig.11 The electronic device according to the embodiment of the present disclosure is described. The electronic device may be any one or both of the first device and the second device, or a stand-alone device independent of them, and the stand-alone device may communicate with the first device and the second device to receive the collected input signals from them.
[0154] like Fig.11 As shown, the electronic device includes one or more processors and memory.
[0155] The processor may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
[0156] The memory may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor may execute the program instructions to implement the data storage method of each embodiment of the present disclosure described above and / or other desired functions.
[0157] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0158] In addition, the input device may also include, for example, a keyboard, a mouse, and the like.
[0159] The output device can output various information to the outside, including the determined distance information, direction information, etc. The output device can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.
[0160] Of course, to simplify, Fig.11 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.
[0161] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the data storage method according to various embodiments of the present disclosure described in the above part of this specification.
[0162] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0163] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, enables the processor to execute the steps of the data storage method according to various embodiments of the present disclosure described in the above part of this specification.
[0164] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0165] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.
[0166] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.
[0167] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0168] The block diagrams of the devices, apparatuses, equipment, and systems involved in this disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including," "comprising," "having," and the like are open words, referring to "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or," and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.
[0169] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.
[0170] It should also be noted that in the apparatus, device and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.
[0171] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0172] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.
Claims
1. A data storage method, characterized in that: Applied to a computing device, the computing device includes a memory pool and an object pool, the method includes: In response to receiving a storage request for target data, storing the target data in the memory pool, and determining a first target object corresponding to the target data based on storage information of the target data in the memory pool; Determining a target memory block among a plurality of memory blocks in the object pool based on a target storage position of the first target object in the circular queue; The first target object is stored in the target memory block.
2. The method according to claim 1, characterized in that: The object pool includes a plurality of continuous index nodes and a plurality of memory segments, and each memory segment includes a plurality of memory blocks; The determining a target memory block from a plurality of memory blocks in the object pool based on a target storage position of the first target object in the ring queue comprises: Based on a mapping relationship between preset index nodes and storage locations, determining a target index node corresponding to a target storage location of the first target object in the ring queue from among the multiple index nodes; Based on a mapping relationship between preset index nodes and memory segments, determining a target memory segment corresponding to the target index node from among the multiple memory segments; The target memory block is determined based on a current memory block in the target memory segment, where the current memory block is a memory block that stores the latest object in the target memory segment.
3. The method according to claim 1 or 2, characterized in that: Before storing the target data in the memory pool and determining the first target object corresponding to the target data based on the storage information of the target data in the memory pool, the method further includes: In response to a data type of the target data being a first preset data type, performing an operation of storing the target data in the memory pool in response to receiving a storage request for the target data, and determining a first target object corresponding to the target data based on storage information of the target data in the memory pool; In response to the data type of the target object being a second preset data type, determining a second target object corresponding to the target data based on data information of the target data; Determining the target memory block based on a target storage position of the second target object in the circular queue; The target data and the second target object are stored in the target memory block.
4. The method according to claim 3, characterized in that After the data type of the target data is the first preset data type, the method further includes: In response to the storage form included in the storage request being queue storage, or the storage form being empty, performing, in response to receiving the storage request for target data, storing the target data in the memory pool, and determining, based on storage information of the target data in the memory pool, an operation of a first target object corresponding to the target data; In response to the storage request including the storage form as default storage, the target data is stored in the system memory of the computing device.
5. The method according to claim 3, characterized in that: The storing the target object into the target memory block comprises: In response to the data type of the target data being the first preset data type, storing the first target object in the target memory block by using move semantics; In response to the data type of the target data being the second preset data type, the target data and the second target object are stored in the target memory block by using copy semantics.
6. The method according to claim 1, characterized in that Also includes: In response to receiving a removal request for target data of a first preset data type, determining the target memory block based on a target storage position of the first target object in the ring queue; The first target object is removed from the target memory block.
7. The method according to claim 3, characterized in that Also includes: In response to receiving a removal request for target data of a second preset data type, determining the target memory block based on a target storage position of the second target object in the ring queue; The target data and the second target object are deleted in the target memory block.
8. The method according to claim 1, characterized in that Also includes: In response to the size of the available storage space in the object pool being less than a first preset threshold, sending a memory segment application request to the memory pool; In response to the size of the comprehensive spare storage space corresponding to the spare memory segment in the memory pool being greater than or equal to a second preset threshold, acquiring a new memory segment from the spare memory segment and allocating it to the object pool; In response to the size of the integrated spare storage space being smaller than the second preset threshold, allocating the new memory segment from the system memory to the object pool.
9. The method according to claim 8, characterized in that Also includes: In response to the size of the available storage space in the object pool being greater than the first preset threshold for a duration exceeding a preset duration, determining a size of the first returned storage space based on the size of the available storage space in the object pool and the first preset threshold; In the object pool, a memory segment that does not store objects and corresponds to the size of the first returned storage space is returned to the memory pool.
10. The method according to claim 9, characterized in that Also includes: In response to the size of the available storage space in the memory pool being less than a preset third preset threshold, acquiring supplementary memory from the system memory to allocate the supplementary memory to the memory pool; In response to the size of the available storage space in the memory pool being greater than the preset third preset threshold for a duration exceeding a preset duration, determining the size of the second returned storage space based on the size of the available storage space in the memory pool and the third preset threshold; In the memory pool, the memory without data stored therein corresponding to the size of the second returned storage space is returned to the system memory.
11. A data storage device, characterized in that: Applied to a computing device, the computing device includes a memory pool and an object pool, and the apparatus includes: an object construction module, configured to, in response to receiving a storage request for target data, store the target data in the memory pool, and determine a first target object corresponding to the target data based on storage information of the target data in the memory pool; A first memory block determination module, configured to determine a target memory block from a plurality of memory blocks in the object pool based on a target storage position of the first target object in the circular queue; A first storage module is used to store the first target object in the target memory block.
12. An electronic device, characterized in that: include: Memory for storing computer programs; A processor is used to execute the computer program stored in the memory, and when the computer program is executed, the data storage method described in any one of claims 1 to 10 is implemented.