A data storage method, system, device and medium based on two-dimensional ID addressing
Patent Information
- Application Number
- CN202311351037.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-18
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2043-10-18
AI Technical Summary
但是在实际应用中,使用三维数组存储数据时,分配固定大小的内存空间,即使实际使用的数据量较小,这种固定大小的内存空间不适用于存储不规则的数据分布,且无法灵活地调整内存空间大小,导致巨大的内存浪费
1.本申请通过获取待存储数据的数据信息,根据预先建立的页面ID索引,在节点数组中快速定位到目标待存储数据对应的页面ID和文本框ID所在的节点。这里通过页面ID索引实现快速定位页面节点,并利用节点数组对应不同页面下的文本框进行二维索引。根据待存储数据的数据长度在数据存储空间中动态分配对应长度的目标存储地址。将目标待存储数据写入前一步分配到的目标存储地址中。通过遍历方式,将后续待存储数据依次作为目标数据,重复上述获取节点地址并存储数据的步骤,直到所有数据都写入存储空间。通过这一过程,实现了基于页面ID和文本框ID进行二维索引的结构化数据存储方法。通过页面ID索引优化节点定位,动态内存分配节约资源,提高了内存空间利用率。
Smart Images

Figure CN117215497B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage technology, specifically to a data storage method, system, device, and medium based on two-dimensional ID addressing. Background Technology
[0002] With the rapid development of information technology and the continuous increase in data volume, the demand for efficient data storage and access methods is becoming increasingly urgent. Especially in large-scale data processing and analysis scenarios, the choice of addressing mode is crucial to system performance and data reliability. In C language software development, especially in C language development for microprocessors, particular emphasis is placed on program reliability and minimizing memory resource consumption.
[0003] Currently, conventional C language operations use three-dimensional arrays for storage. However, in practical applications, using three-dimensional arrays to store data allocates a fixed amount of memory. Even if the actual amount of data used is small, this fixed-size memory space is not suitable for storing irregularly distributed data and cannot flexibly adjust the memory space size, resulting in huge memory waste. Summary of the Invention
[0004] This application provides a data storage method, system, electronic device, and medium based on two-dimensional ID addressing, which can improve memory space utilization.
[0005] Firstly, this application provides a two-dimensional ID addressing method in C language, including: Obtain data information for at least one piece of data to be stored, the data information including the page ID of the page where the data to be stored is located, the text box ID of the text box in the page, and the data length of the data to be stored; Get the target data to be stored that is currently being traversed. Based on the preset page ID index, find the node corresponding to the page ID and text box ID of the target data to be stored in the node array. The node includes a data space address. The node array includes a row of nodes corresponding to different page IDs. Each row of nodes corresponds one-to-one with the text box ID contained in the page corresponding to the same page ID. The data space address of the node points to the storage space. Based on the data length of the data to be stored, allocate a corresponding target storage space in the data space, and store the target data to be stored in the target storage space; Traverse the next data to be stored, take the next data to be stored as the target data to be stored, and execute the step of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array until all the data to be stored is stored in the corresponding storage space.
[0006] By adopting the above technical solution, the system first obtains the data information of the data to be stored, including the page ID, text box ID, and data length. This identifies the page to which the data to be stored belongs and the position of the text box within that page, achieving data identification through two-dimensional indexing. Then, based on the pre-established page ID index, the system quickly locates the node containing the page ID and text box ID corresponding to the target data to be stored in the node array. Here, the page ID index is used to quickly locate the page node, and the node array is used to perform two-dimensional indexing of the text boxes under different pages. The node also includes data address information, pointing to the actual data storage space. Next, a target storage address of the corresponding length is dynamically allocated in the data storage space according to the data length of the data to be stored. This achieves dynamic allocation of storage space, saving memory resources. Then, the target data to be stored is written into the target storage address allocated in the previous step. At this point, the storage process for one piece of data is completed. Finally, by traversing the data, subsequent data to be stored are used as target data in sequence, and the above steps of obtaining node addresses and storing data are repeated until all data is written into the storage space. Through this process, a structured data storage method based on two-dimensional indexing using page ID and text box ID is realized. Optimizing node location through page ID indexing and dynamically allocating memory saves resources and improves memory space utilization.
[0007] Optionally, an initial page ID index is created, which is a data structure; the node array is traversed to obtain the starting node corresponding to each page ID; each page ID is used as a key and the starting node corresponding to each page ID is used as a value to add to the initial page ID index to obtain the preset page ID index.
[0008] By adopting the above technical solution, the system first creates an empty initial page ID index data structure, which is used for index management. Then, it traverses the entire node array to obtain the first node corresponding to each page ID, i.e., the starting node. Each page ID is used as the index key, and the corresponding starting node as the value, and added to the initial page ID index data structure. Through the above steps, a complete mapping of starting nodes corresponding to page IDs is constructed. Here, the page ID is used as the key index, and the first node of the corresponding page is quickly located. This realizes an index structure for quickly finding the storage location of the corresponding node based on the page ID, finally obtaining the preset page ID index. This serves as the basic data structure for subsequent rapid node location based on the preset page ID, achieving the technical effect of rapid jump to the target node. This process, by establishing a mapping table between page IDs and nodes, realizes a technical framework for two-dimensional index location based on page IDs, laying the technical foundation for efficient data storage using this index.
[0009] Optionally, the data space is obtained; according to a preset space division standard, the data space is divided into several storage spaces of different byte sizes; among the several storage spaces of different byte sizes, a target storage space matching the data length of the data to be stored is determined, and the target storage space is allocated.
[0010] By adopting the above technical solution, the system obtains the available data space provided by the system. Then, according to preset rules, the data space is divided into multiple fixed-length storage segments, i.e., storage spaces, each segment may have a different length. This achieves adaptive allocation of storage space. Next, these storage segments of different lengths are traversed, and the matching target storage space, i.e., the target storage space, is located based on the actual length of the data to be stored. The target storage space of the matching length is then formally allocated. Through this dynamic matching allocation mechanism, the data length is adapted to the actual length of the storage space occupied, thus improving memory utilization. Compared with traditional static allocation of storage blocks, this dynamic allocation method based on actual needs can better adapt to the uncertainty of data length and is a memory management method that optimizes resource utilization.
[0011] Optionally, traverse each node in the node array; record the current number of allocated storage spaces and use the number of allocated spaces as an allocation item flag; initialize the next node pointer in each node to be allocated to an empty state and initialize the text box ID in each node to be allocated to 0xFF as a flag indicating that the node is not allocated; initialize the page ID index to 0xFF as a flag indicating that there is no starting node; set the allocation item flag of the allocated array space to 0 as a flag indicating that allocation starts from the 0th array space; the step of allocating the corresponding target storage space in the data space according to the data length of the data to be stored includes: according to the data length of the data to be stored, allocating the corresponding target storage space to the nodes corresponding to the page ID and text box ID of the target data to be stored in the node array after setting the flag information.
[0012] By adopting the above technical solution, the system first traverses the entire node array and initializes each node. Then, it records the number of allocated storage blocks as an allocation counter flag, i.e., an allocation item flag. Next, it sets the next pointer of each node to null, the text box ID to the unallocated flag 0xFF, and the page ID index to the no-start flag 0xFF. Furthermore, it resets the storage allocation counter to 0, indicating that allocation starts from the first block. These steps perform a full-range initialization of node data and storage space related information. This ensures that the nodes and storage space data are initially in a preset "blank" state. Then, based on the length of the data to be stored, it finds the corresponding page ID and text box ID node in this pre-set node array and allocates it. The combination of full initialization and dynamic allocation achieves optimal memory utilization while ensuring the consistency and traceability of node data.
[0013] Optionally, determine whether the text box ID and the page ID of the node exceed the preset number limit; if the text box ID and the page ID exceed the preset number limit, return a null value; if the text box ID and the page ID do not exceed the preset number limit, traverse the preset page ID index to determine whether a starting node exists; if the starting node does not exist, allocate a new node as the node corresponding to the page ID and text box ID of the target data to be stored.
[0014] By adopting the above technical solution, the system first determines whether the page ID and text box ID of the data to be stored exceed the preset number limit. If the page ID and text box ID exceed the limit, an invalid value is returned to avoid errors. If they do not exceed the limit, the system traverses according to the preset page ID index. Then, it checks whether there is a starting node record for the page ID. If there is no record, it means that no node has been allocated for this page. Therefore, a new node is directly allocated as the storage location of the target data in the node array. This process achieves the following: verifying the validity of the ID to avoid incorrect storage; using the page ID index to locate the starting node position, and creating a new node if it does not exist to achieve dynamic allocation, thereby locating and obtaining the specific storage address of the target data in the node array as the basis for subsequent storage. This ensures the integrity and storage efficiency of the structured index and is an important pre-process for addressing and allocation.
[0015] Optionally, if the starting node exists, the text box ID of the target data to be stored is compared with the text box ID of the starting node; if the text box ID of the target data to be stored is the same as the text box ID of the starting node, the starting node is used as the node corresponding to the page ID and text box ID of the target data to be stored; if the text box ID of the target data to be stored is different from the text box ID of the starting node, it is checked whether the next node pointer in the starting node points to an empty link; if the next node pointer in the starting node points to an empty link, it is determined that the starting node is located at the end of the node array, and a node is added at the end position, and the added node is used as the node corresponding to the page ID and text box ID of the target data to be stored; if the next node pointer in the starting node points to the next node, the step of comparing the text box ID of the target data to be stored with the text box ID of the next node is repeated.
[0016] By adopting the above technical solution, the system first searches for the corresponding starting node in the page ID index based on the page ID. If no starting node exists, a new node is directly allocated to store the target data. If a starting node exists, it is necessary to traverse sequentially from the starting node, determining whether the text box ID of each node matches the text box ID of the target data. The specific traversal process involves comparing the text box ID of the target data with the text box ID of the starting node. If they are the same, the starting node is directly determined as the target storage node. If they are different, it is necessary to check whether the next node pointer of the starting node is null, i.e., whether it points to an empty link. If the next node pointer is null, it means that the end of the node array has been reached, and a new node is added at the end as the target storage node. If the next node pointer is not null, the traversal continues, comparing the target text box ID with the next node, and repeating this traversal and judgment process. This traversal matching method can sequentially search for the storage node corresponding to the target data when a starting node exists. If no matching node exists, a new node is added at the end for storage. This can quickly locate the storage location of each piece of data, improving storage efficiency, without having to traverse the entire node array from the beginning, thus optimizing the search logic.
[0017] Optionally, it can be detected whether the target data to be stored in the storage space is empty; if the target data to be stored in the storage space is empty, the step of storing the target data to be stored in the storage space of the node is repeated; if the target data to be stored in the storage space is not empty, the data length of the target data to be stored is stored in a preset length variable, and the preset length variable is stored in the node.
[0018] By adopting the above technical solution, after the system writes data to the node's storage space, it reads the written data and checks whether it is empty. This checks whether the pointer is a null pointer or whether the content is completely empty. If the check result is empty, it means that invalid empty data was written, and the data writing process is repeated. This writing and checking process is repeated until valid non-empty data is read and written. Then, the length of the non-empty data is read and stored in a preset length variable, and the length variable is simultaneously written to the current node to complete the length storage. This detection and repeated writing mechanism can prevent empty data from being stored, ensuring that the data in the storage space is valid. It also facilitates subsequent readings by determining the data size using the length information, avoiding anomalies caused by storing empty data.
[0019] A second aspect of this application provides a system for a data storage method based on two-dimensional ID addressing.
[0020] The information acquisition module is used to acquire data information of at least one piece of data to be stored, the data information including the page ID of the page where the data to be stored is located, the text box ID of the text box in the page, and the data length of the data to be stored; The node query module is used to obtain the target data to be stored that is currently being traversed. Based on the preset page ID index, it searches in the node array for the node corresponding to the page ID and text box ID of the target data to be stored. The node includes a data space address. The node array includes a row of nodes corresponding to different page IDs. Each row of nodes corresponds one-to-one with the text box ID contained in the page corresponding to the same page ID. The data space address of the node points to the storage space. The data storage module is used to allocate a corresponding target storage space in the data space according to the data length of the data to be stored, and to store the target data to be stored into the target storage space; The circular storage module is used to traverse the next data to be stored, take the next data to be stored as the target data to be stored, and perform the step of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array until all the data to be stored is stored in the corresponding storage space.
[0021] A third aspect of this application provides an electronic device.
[0022] A system for a data storage method based on two-dimensional ID addressing includes a memory, a processor, and a program stored in the memory and executable on the processor. When the program is loaded and executed by the processor, it implements a data storage method based on two-dimensional ID addressing.
[0023] A fourth aspect of this application provides a computer-readable storage medium.
[0024] A computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement a data storage method based on two-dimensional ID addressing.
[0025] In summary, one or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. This application obtains the data information of the data to be stored and, based on a pre-established page ID index, quickly locates the node containing the page ID and text box ID corresponding to the target data to be stored in the node array. Here, page ID indexing is used to quickly locate page nodes, and the node array is used to perform a two-dimensional indexing of text boxes under different pages. A target storage address of the corresponding length is dynamically allocated in the data storage space according to the data length of the data to be stored. The target data to be stored is written to the target storage address allocated in the previous step. By traversing, subsequent data to be stored is used as target data in turn, and the above steps of obtaining node addresses and storing data are repeated until all data is written to the storage space. Through this process, a structured data storage method based on a two-dimensional index using page ID and text box ID is realized. Optimizing node location through page ID indexing and saving resources through dynamic memory allocation improves memory space utilization.
[0026] 2. This application creates an empty initial page ID index data structure, traverses the entire node array, and obtains the first node corresponding to each page ID, i.e., the starting node. Each page ID is used as the index key, and the corresponding starting node is used as the value, added to the initial page ID index data structure. Through the above steps, a complete mapping of starting nodes corresponding to page IDs is constructed. Here, the page ID is used as the key index, and the first node of the corresponding page is quickly located using the page ID as the index. This implements an index structure for quickly finding the storage location of the corresponding node based on the page ID, finally obtaining the preset page ID index. This serves as the basic data structure for subsequently quickly locating nodes based on the preset page ID, achieving the effect of rapid jump to the target node.
[0027] 3. This application obtains data space provided by the system. Then, according to preset rules, the data space is divided into multiple fixed-length storage segments, each of which may have a different length. This achieves adaptive allocation of storage space. These storage segments of different lengths are traversed, and based on the actual length of the data to be stored, a matching target storage space is located, i.e., the target storage space. Finally, the target storage space of the matching length is formally allocated. Through this dynamic matching allocation mechanism, the data length is adapted to the actual length of the storage space occupied, improving memory utilization. Attached Figure Description
[0028] Figure 1 This is a flowchart illustrating a data storage method based on two-dimensional ID addressing provided in an embodiment of this application.
[0029] Figure 2 This is a schematic diagram of a data storage method based on two-dimensional ID addressing for node lookup provided in an embodiment of this application.
[0030] Figure 3 This is a schematic diagram of the structure of a data storage system based on two-dimensional ID addressing disclosed in an embodiment of this application.
[0031] Figure 4 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application.
[0032] Explanation of reference numerals in the attached diagram: 301, Information acquisition module; 302, Node query module; 303, Data storage module; 304, Circular storage module; 400, Electronic device; 401, Processor; 402, Memory; 403, User interface; 404, Network interface; 405, Communication bus. Detailed Implementation
[0033] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0034] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.
[0035] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.
[0036] To facilitate understanding of the methods and systems provided in the embodiments of this application, the background of the embodiments of this application will be introduced before introducing the embodiments of this application.
[0037] Currently, conventional C language operations use three-dimensional arrays for storage. Three-dimensional arrays require a fixed amount of memory to be pre-allocated at compile time. However, real-world applications often have irregular data distributions, and the data volume may be much smaller than the pre-allocated memory size, leading to significant memory waste. Furthermore, the memory size of a three-dimensional array cannot be dynamically adjusted. Once allocated, the memory size is fixed. If the data changes significantly later, the storage structure cannot be effectively adjusted, resulting in inefficient memory utilization.
[0038] Overall, directly using three-dimensional arrays to store data has certain limitations in terms of memory utilization and storage structure flexibility, which can lead to memory waste.
[0039] This application discloses a data storage method based on two-dimensional ID addressing. By acquiring target area storage information, the method searches for the corresponding node in a preset page ID index based on the page ID and text box ID in the target area storage information, and then stores the target data in storage space with an allocation size appropriate to the data length. This method primarily addresses the problem of excessive memory waste when using conventional three-dimensional arrays for data storage in C language design for microprocessors.
[0040] Having read the background information above, those skilled in the art can understand the problems existing in the prior art. The technical solutions in the embodiments of this application will be described in detail below with reference to the accompanying drawings. The described embodiments are only some embodiments of this application, and not all embodiments.
[0041] Reference Figure 1 A data storage method based on two-dimensional ID addressing, comprising steps S10 to S40, specifically including the following steps: S10: Obtain data information for at least one piece of data to be stored. The data information includes the page ID of the page where the data to be stored is located, the text box ID of the text box in the page, and the data length of the data to be stored.
[0042] The text box ID is used to abstract and identify the individual text boxes on the page. Since each page may contain multiple text boxes, the ID is used to distinguish which text box is which. For example, the first text box on page A is numbered "1", the second is numbered "2", and so on.
[0043] A page ID is an abstract number that identifies the entire page. Since a system may contain multiple pages, an ID is needed to identify which page it is. For example, the first page is numbered "1", the second page is numbered "2", and so on.
[0044] The data length refers to the actual byte length of the string data to be stored in the text box. Since different strings have different lengths, the length of each string data segment needs to be recorded for accurate storage.
[0045] Specifically, in microprocessor-controlled scenarios, text data in different pages and their text boxes needs to be stored and retrieved in real time. In practice, the system needs to obtain the source code of the display page currently controlled by the microprocessor. By parsing the source code, it can obtain the numbers of all text boxes (text box IDs) contained on that page, as well as the page's own number (page ID). Each text box on the page is traversed to determine if it contains the text content to be stored. If it does, the text box ID and the page ID of the page containing it are recorded. Furthermore, to accurately store the data length, the actual byte length of the text data is calculated, i.e., the data length. The obtained page ID, text box ID, and data length corresponding to a piece of data to be stored are integrated into a dataset to form complete information about this data. By extracting complete information for each piece of data to be stored in this way, a foundation can be laid for subsequent storage and access. Precise ID positioning can determine the text location, and data length information can support precise memory allocation. This will make data storage and access truly efficient and accurate, well meeting the requirements of microprocessor projects for memory efficiency and reliability. The above is the specific implementation method of this technical step, which aims to provide accurate and effective input for subsequent work to optimize the overall process.
[0046] S20: Obtain the target data to be stored that is currently being traversed. Based on the preset page ID index, find the node corresponding to the page ID and text box ID of the target data to be stored in the node array. The node includes a data space address. The node array includes a row of nodes corresponding to different page IDs. Each row of nodes corresponds one-to-one with the text box ID contained in the page corresponding to the same page ID. The data space address of the node points to the storage space.
[0047] The preset page ID index is an index data structure used to map and locate the starting position of the node array corresponding to each page ID.
[0048] A node is a data structure that includes: a text box ID, used to identify the text box containing the corresponding data; a data space address, used to point to the memory address of the actual data block; a data length, used to record the actual length of the stored data; and a next node pointer, used to link to the next associated node. Nodes are used to locate and manage the access of a piece of actual data in memory.
[0049] A node array is a pre-created array of complete structures. It consists of numerous node data structure elements, providing space for storing and managing nodes. Each node has a unique number within the array, allowing for quick access to the specific node by number. The node array's array format enables efficient management of a large number of nodes, facilitates the establishment of relationships between nodes (such as links via pointers), and supports dynamic allocation of node space. The node array acts as a medium for background storage and management of nodes; its array storage format lays the foundation for subsequent efficient access and manipulation of nodes. Nodes are used to represent and manipulate individual pieces of data; node arrays are used to efficiently manage and link all node relationships.
[0050] Specifically, after acquiring the data to be stored, the system can directly locate the row in the node array corresponding to the page ID using a preset page ID index. It then obtains detailed records of the data to be processed, including the page ID and text box ID. Based on these two pieces of information, it performs a sequential matching comparison from beginning to end in the corresponding row. It should be noted that each node not only contains a data pointer but also corresponds to a specified text box, and a one-to-one matching of the target data ID with the node ID is performed. Once a node with a completely matching text box ID is found in the node array, it is the node where the target data is stored. Since the node also directly points to the actual data block, subsequent write steps must be prepared at this point. Using this method, even with large-scale data volumes, the system can efficiently and accurately guide the target data to a specific unit in the memory array using page indexing and node array lookup functions, thus achieving optimized data management.
[0051] Reference Figure 2 Based on the above embodiments, the specific steps of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array according to the preset page ID index further include S21 to S22: S21: Determine whether the text box ID and page ID of the node exceed the preset number limit; if the text box ID and page ID exceed the preset number limit, return null; if the text box ID and page ID do not exceed the preset number limit, traverse the preset page ID index to determine whether a starting node exists; if no starting node exists, allocate a new node as the node corresponding to the page ID and text box ID of the target data to be stored.
[0052] For example, the system obtains the page ID and text box ID from the data record to be stored. Then, it needs to determine whether these two IDs exceed a preset maximum value range. This determination process identifies potential errors and prevents anomalies in subsequent processing. If the text box ID and page ID do not exceed the limits, the system proceeds to the next step. The system locates the corresponding starting node using the page ID index. If no matching starting node is found after traversing the index, it indicates a defect in the node structure. To ensure the continuity of subsequent processes, a new node needs to be created to fill this "blank" position. The newly generated node lays the foundation for subsequent data storage, and the text box ID and page ID verification enhances the reliability of subsequent matching. Through text box ID and page ID filtering and node supplementation, this implementation enhances the robustness and stability of the overall algorithm, ensuring smooth data processing.
[0053] S22: If a starting node exists, compare the text box ID of the target data to be stored with the text box ID of the starting node; if the text box ID of the target data to be stored is the same as the text box ID of the starting node, then use the starting node as the node corresponding to the page ID and text box ID of the target data to be stored; if the text box ID of the target data to be stored is different from the text box ID of the starting node, check whether the next node pointer in the starting node points to an empty link; if the next node pointer in the starting node points to an empty link, then determine that the starting node is located at the end of the node array, and add a node at the end, using the added node as the node corresponding to the page ID and text box ID of the target data to be stored; if the next node pointer in the starting node points to the next node, repeat the step of comparing the text box ID of the target data to be stored with the text box ID of the next node.
[0054] The default function inserts nodes into the page chain and automatically allocates storage space as needed. Its parameters are the left node, the right node, and the text box number of the node to be allocated. The function updates the pointer to the new node based on the passed left and right nodes and sets the text box number of the new node. Then, based on the size allocated during the current data write process, it automatically allocates storage space and saves the address and size of the space to the new node. For example, if the starting node has already been created, the traversal process begins. The system initializes two pointer variables using a preset function, pointing to the starting node and the next node, respectively. Next, the preset function checks if the starting node is the node being searched for. If so, it returns the node pointer depending on whether data is being written, or saves the current amount of data being written to the node and returns the node pointer. If the text box number of the node being searched for is less than the text box number of the starting node, a new node needs to be inserted as the starting node. The head of the chain is updated, and the preset function is called to create and insert the new node. If the next node of the starting node is null, the chain has been traversed to the end, and a new node needs to be inserted at the tail. The tail of the chain is updated, and the preset function is called to create and insert the new node. If the text box number of the node being searched for is between the starting node and the next node, a new node needs to be inserted between the two nodes, and the preset function is called to create and insert the new node. If none of the above conditions are met, the linked list traversal continues. The system iterates through the linked list using the preset function until the end of the chain is reached. During traversal, the predefined function updates the pointers to the current and next nodes and checks if the desired node has been found. If found, it returns the node pointer depending on whether data is being written, or saves the current amount of data being written to the node and returns the node pointer. If the desired node is not found after traversing the entire linked list, it means a new node needs to be inserted at the end of the list, and the function is called to create and insert the new node.
[0055] S30: Based on the length of the data to be stored, allocate the corresponding target storage space in the data space, and store the target data to be stored in the target storage space.
[0056] The data space is the area of computer memory used to store and manage data and programs. Computer memory can be divided into multiple units, each with a unique address for accessing and storing data. In a program, memory space is used to store variables, objects, functions, and other data structures.
[0057] The target storage space is a memory block allocated based on the length of the data to be stored. The system uses a pre-allocation method to plan the "data space," resulting in multiple memory blocks of different byte sizes. After obtaining the information of each piece of data to be stored and its length, the system needs to select the most matching memory region from the data space blocks based on the length. This independent memory unit, allocated through matching to serve specific data, serves as the "target storage space." It is an independent memory block dynamically allocated for each piece of data to be stored, linked to the corresponding data node via pointers. The node is only responsible for storing pointers to the target storage space, achieving secure isolation between data and storage. The target storage space is directly used to store the actual content of the data. By allocating a dedicated area for each piece of data, the system solves the memory pointer vulnerability and supports dynamic allocation and efficient storage management.
[0058] Specifically, based on the length of the data to be stored, the system dynamically allocates a "target storage space" from the preset "data space" whose size in bytes best matches the length of the data to be stored.
[0059] Here, the "data space" is pre-divided into storage units of different lengths, and the "target storage space" is the matched and allocated storage unit. After allocation, the allocation information is recorded and saved to the corresponding "target data node," establishing a connection. The actual content of the data to be stored is directly and sequentially written to the newly allocated "target storage space" area through the node pointer. This process completely solves the safety problem of directly manipulating pointers, while achieving flexible and efficient storage management. Each data has an independent and optimized area, and allocation is dynamically matched. Memory resources are used efficiently, and nodes act as a bridge to complete the two-way communication between the algorithm and physical storage. The C language data management process is implemented, and the process from acquisition to precise memory allocation and content writing is well solved.
[0060] In one optional embodiment of this application, an initialization step is performed before allocating the target storage space for data storage. Specifically, the system traverses the node array, recording the current number of allocated storage units as an allocation item flag, which indicates which storage space has been allocated. The next pointer and text box ID of each node to be allocated are set to the default unallocated state (0xFF). The page ID index and the allocation item flag of the allocated space are also initialized to 0xFF, indicating that allocation starts from the 0th storage space. This initialization process has two important implications: first, it pre-verifies and cleans up the node state, eliminating any residual information that could affect subsequent operations; second, it uses a unified identifier to provide a clean and tidy base for matching, allocation, and other steps. After initialization, the target node can be quickly located in the pre-processed node array based on the data length. Storage units are then dynamically allocated according to the length, completing the matching of memory and data. This initialization process improves the coherence and security of subsequent processes.
[0061] S40: Traverse the next data to be stored, take the next data to be stored as the target data to be stored, and perform the step of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array, until all data to be stored is stored in the corresponding storage space.
[0062] Specifically, the system predefines a set of data to be stored, initialized to 0, to record the index of the currently processed data to be stored. Then, a loop is entered, and each time, the data at index `index` is read from the set of data to be stored as the target data to be stored. The process of finding the corresponding storage node for this target data is performed, specifically by searching for a matching node in the node array using its page ID and text box ID. After finding a matching node, the target data to be stored is written into the storage space corresponding to that node. After writing, `index` is incremented by 1, pointing to the next data to be stored. This process of finding matching nodes and writing data is then repeated. Through this traversal logic, each piece of data to be stored can be retrieved sequentially, its storage location in the node array can be found, and it can be written into the corresponding storage space. The traversal process ends when all data has been traversed to the index, meaning all data has been stored in the corresponding storage node. This allows for the orderly processing of all data to be stored by simply traversing the index, and correctly storing it into the preset node storage space. This ensures that all data is stored in the specified location, without omission or duplication, improving storage integrity.
[0063] In another optional embodiment of this application, after each time the data to be stored is stored into the corresponding storage space, a data update step is further included, specifically step S41: S41: Detect whether the target data to be stored in the storage space is empty; if the target data to be stored in the storage space is empty, repeat the step of storing the target data to be stored in the node's storage space; if the target data to be stored in the storage space is not empty, store the data length of the target data to be stored in the preset length variable, and store the preset length variable in the node.
[0064] Here, "empty data" refers to the situation where the actual data to be stored is empty. After retrieving the data to be stored, it needs to be written to the pre-allocated storage node. However, due to read errors or the content itself lacking valid information, the retrieved data to be stored may be empty. If such empty data is stored directly, storage space will be occupied without actual data. This wastes storage resources and increases the complexity of storage management. Therefore, the technical solution incorporates an empty data detection mechanism. Before each storage operation, the system compares whether the data to be stored is a null pointer or whether the content consists entirely of empty characters to determine if it is empty data. If it is determined to be empty data, it cannot be stored directly; new data must be read and checked repeatedly until non-empty data is obtained before the actual storage process is executed. This empty data detection method can prevent empty data from being stored in the storage node, ensuring that the data in the storage space is valid, thereby improving storage reliability, saving storage resources, and facilitating subsequent storage management.
[0065] For example, after storing the target data into the node's storage space, the system needs to check whether the actually stored data is empty. Specifically, a flag is defined and initialized to 1 to indicate that the data to be stored may be empty. Data stored in the storage space is read, and its emptiness is determined by checking if the starting address of the data is a null pointer or by iterating through the data content to see if it is entirely empty. If the data to be stored is determined to be empty, the flag remains at 1, indicating that the data is empty. The data storage process is then repeated, continuing to read the next piece of data to be stored until a non-empty piece of data is found. When the data to be stored is determined to be not empty, the flag is set to 0 to indicate that the stored data is valid. Subsequently, the data length is read and stored in a predefined length variable, and simultaneously written to the current node, completing the storage of both the data and its length. This method of repeatedly storing data until valid data is read avoids storing empty data, ensuring that all data in the storage space is valid and improving storage reliability. Storing the data length also facilitates subsequent readings to determine the data size, reducing the complexity of storage management.
[0066] The following are system embodiments of this application, which can be used to execute the method embodiments of this application. For details not disclosed in the platform embodiments of this application, please refer to the method embodiments of this application.
[0067] Reference Figure 3 This application provides a system for a data storage method based on two-dimensional ID addressing. The system includes: an information acquisition module 301, a node query module 302, a data storage module 303, and a circular storage module 304, wherein: The information acquisition module (301) is used to acquire data information of at least one piece of data to be stored. The data information includes the page ID of the page where the data to be stored is located, the text box ID of the text box in the page, and the data length of the data to be stored. The node query module (302) is used to obtain the target data to be stored that is currently being traversed. Based on the preset page ID index, it searches for the node corresponding to the page ID and text box ID of the target data to be stored in the node array. The node includes a data space address. The node array includes a row of nodes corresponding to different page IDs. Each row of nodes corresponds one-to-one with the text box ID contained in the page corresponding to the same page ID. The data space address of the node points to the storage space. The data storage module (303) is used to allocate a corresponding target storage space in the data space according to the data length of the data to be stored, and to store the target data to be stored into the target storage space; The circular storage module (304) is used to traverse the next data to be stored, take the next data to be stored as the target data to be stored, and perform the steps of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array until all data to be stored is stored in the corresponding storage space.
[0068] It should be noted that the above embodiments of the apparatus are only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0069] This application also discloses an electronic device. (See reference...) Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. The electronic device 400 may include: at least one processor 401, at least one network interface 404, a user interface 403, a memory 402, and at least one communication bus 405.
[0070] The communication bus 405 is used to enable communication between these components.
[0071] The user interface 403 may include a display interface and a camera interface. Optionally, the user interface 403 may also include a standard wired interface and a wireless interface.
[0072] The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).
[0073] The processor 401 may include one or more processing cores. The processor 401 connects to various parts of the server using various interfaces and lines, and performs various server functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 402, and by calling data stored in memory 402. Optionally, the processor 401 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 401 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface graphics, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 401 and may be implemented as a separate chip.
[0074] The memory 402 may include random access memory (RAM) or read-only memory. Optionally, the memory 402 may include a non-transitory computer-readable storage medium. The memory 402 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 402 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 402 may also be at least one storage device located remotely from the aforementioned processor 401. (Refer to...) Figure 4 The memory 402, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program based on a two-dimensional ID addressing data storage method.
[0075] exist Figure 4 In the illustrated electronic device 400, the user interface 403 is mainly used to provide an input interface for the user and to acquire user input data; while the processor 401 can be used to call an application program stored in the memory 402 that uses a data storage method based on two-dimensional ID addressing. When executed by one or more processors 401, the electronic device 400 performs one or more methods as described in the above embodiments. It should be noted that, for the foregoing method embodiments, for the sake of simplicity, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0076] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0077] In the various embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between apparatuses or units may be electrical or other forms.
[0078] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0079] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0080] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0081] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will be readily apparent to those skilled in the art upon consideration of the specification and the disclosure of practical truths.
[0082] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
Claims
1. A data storage method based on two-dimensional ID addressing, characterized in that, include: Obtain data information for at least one piece of data to be stored, the data information including the page ID of the page where the data to be stored is located, the text box ID of the text box in the page, and the data length of the data to be stored; Get the target data to be stored that is currently being traversed. Find the node corresponding to the page ID and text box ID of the target data to be stored in the node array according to the preset page ID index. The node includes a data space address, text box ID, data length and next node pointer. The node array includes a row of nodes corresponding to different page IDs. Each row of nodes corresponds one-to-one with the text box IDs contained in the page corresponding to the same page ID. The data space address of the node points to the storage space. Based on the data length of the data to be stored, allocate a corresponding target storage space in the data space, and store the target data to be stored in the target storage space; Traverse the next data to be stored, take the next data to be stored as the target data to be stored, and execute the step of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array until all data to be stored is stored in the corresponding storage space; Before searching for the node corresponding to the page ID and text box ID of the target data to be stored in the node array according to the preset page ID index, the method further includes: Create an initial page ID index, which is a data structure; Traverse the node array to obtain the starting node corresponding to each page ID; The preset page ID index is obtained by adding the page ID as the key and the starting node corresponding to each page ID as the value to the initial page ID index.
2. The data storage method based on two-dimensional ID addressing according to claim 1, characterized in that, The step of allocating a corresponding target storage space in the data space according to the data length of the data to be stored includes: Obtain data space; According to the preset space division standard, the data space is divided into several storage spaces of different byte sizes; Determine a target storage space that matches the data length of the data to be stored from several storage spaces of different byte sizes, and allocate the target storage space.
3. The data storage method based on two-dimensional ID addressing according to claim 1, characterized in that, Before allocating corresponding storage space based on the data length of the data to be stored, the method further includes: Iterate through each node in the node array; Record the number of current storage space allocations and use the number of allocations as an allocation item flag; The pointers of the next node in each node to be assigned are initialized to an empty state, and the text box IDs in each node to be assigned are initialized to 0xFF as a flag indicating that the node has not been assigned. The page ID index is initialized to 0xFF as a flag indicating that there is no starting node; Set the allocation item flag of the allocated array space to 0 as a flag indicating that allocation starts from the 0th array space; The step of allocating a corresponding target storage space in the data space according to the data length of the data to be stored includes: Based on the length of the data to be stored, allocate corresponding target storage space to the nodes corresponding to the page ID and text box ID of the target data to be stored in the node array after setting the flag information.
4. The data storage method based on two-dimensional ID addressing according to claim 1, characterized in that, The step of searching for the node corresponding to the page ID and text box ID of the target data to be stored in the node array according to the preset page ID index includes: Determine whether the text box ID of the node and the page ID exceed the preset number limit; If the text box ID and the page ID exceed the preset number limit, then return an empty value; If the text box ID and the page ID do not exceed the preset number limit, then traverse the preset page ID index to determine if there is a starting node; If the starting node does not exist, a new node is assigned as the node corresponding to the page ID and text box ID of the target data to be stored.
5. The data storage method based on two-dimensional ID addressing according to claim 4, characterized in that, The starting node includes a next node pointer and a text box ID. After determining whether a starting node exists, the process further includes: If the starting node exists, then compare the text box ID of the target data to be stored with the text box ID of the starting node; If the text box ID of the target data to be stored is the same as the text box ID of the starting node, then the starting node is used as the node corresponding to the page ID and text box ID of the target data to be stored. If the text box ID of the target data to be stored is different from the text box ID of the starting node, then check whether the next node pointer in the starting node points to an empty link; If the next node pointer in the starting node points to an empty link, it is determined that the starting node is located at the end of the node array, and a node is added at the end position. The added node is used as the node corresponding to the page ID and text box ID of the target data to be stored. If the next node pointer in the starting node points to the next node, then repeat the step of comparing the text box ID of the target data to be stored with the text box ID of the next node.
6. The data storage method based on two-dimensional ID addressing according to claim 1, characterized in that, After storing the target data to be stored into the storage space of the node, the method further includes: Detect whether the target data to be stored in the storage space is empty; If the target data to be stored in the storage space is empty data, then repeat the step of storing the target data to be stored in the storage space of the node. If the target data to be stored in the storage space is not empty, then the data length of the target data to be stored is stored in a preset length variable, and the preset length variable is stored in the node.
7. A data storage method system based on two-dimensional ID addressing, characterized in that, The system includes: The information acquisition module (301) is used to acquire data information of at least one piece of data to be stored, the data information including the page ID of the page where the data to be stored is located, the text box ID of the text box in the page, and the data length of the data to be stored; The node query module (302) is used to obtain the target data to be stored that is currently being traversed, and to find the node corresponding to the page ID and text box ID of the target data to be stored in the node array according to the preset page ID index. The node includes a data space address, a text box ID, a data length and a pointer to the next node. The node array includes a row of nodes corresponding to different page IDs. Each row of nodes corresponds one-to-one with the text box IDs contained in the page corresponding to the same page ID. The data space address of the node points to the storage space. The data storage module (303) is used to allocate a corresponding target storage space in the data space according to the data length of the data to be stored, and to store the target data to be stored into the target storage space; The circular storage module (304) is used to traverse the next data to be stored, take the next data to be stored as the target data to be stored, and execute the step of finding the node corresponding to the page ID and text box ID of the target data to be stored in the node array until all data to be stored is stored in the corresponding storage space. Before searching for the node corresponding to the page ID and text box ID of the target data to be stored in the node array according to the preset page ID index, the method further includes: Create an initial page ID index, which is a data structure; Traverse the node array to obtain the starting node corresponding to each page ID; The preset page ID index is obtained by adding the page ID as the key and the starting node corresponding to each page ID as the value to the initial page ID index.
8. An electronic device, characterized in that, The device includes a processor (401), a memory (402), a user interface (403), and a network interface (404). The memory (402) is used to store instructions. The user interface (403) and the network interface (404) are used to communicate with other devices. The processor (401) is used to execute the instructions stored in the memory (402) to cause the electronic device (400) to perform a data storage method based on two-dimensional ID addressing as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the steps of a data storage method based on two-dimensional ID addressing as described in any one of claims 1-6.
Citation Information
Patent Citations
Data storage management method and device
CN104008111A
Data storage method and system and terminal device
WO2020041928A1