Memory management method and device, electronic equipment and computer storage medium

By replacing the static structure array in the ASN.1 file as dynamic pointer elements and dynamic memory management in the C/C++ library file, the problem of excessive memory usage after ASN.1 is solved, and efficient memory utilization is achieved.

CN119690643APending Publication Date: 2025-03-25深圳市微合科技有限公司
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411562616.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-04
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

When ASN.1 is converted to C/C++ code, a large number of redundant structure arrays are generated, resulting in excessive memory usage, and the existing technology has failed to effectively solve this problem.

Method used

Add dynamic memory flags by getting the ASN file, detecting the static structure array element, and replacing it with a dynamic pointer element. When converted to C/C++ library files, a pointer data structure is generated and dynamic memory management is performed according to dynamic memory flags.

Benefits of technology

It greatly reduces static memory footprint, optimizes the C/C++ library files generated by ASN files, avoids memory waste, and improves memory utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690643A_ABST
    Figure CN119690643A_ABST
Patent Text Reader

Abstract

The invention discloses a memory management method and device, electronic equipment and a computer storage medium, and belongs to the field of data communication and software engineering. The method comprises the following steps: acquiring an abstract syntax mark ASN file, and detecting a static structure array element in the ASN file; replacing the static structure array element with a dynamic pointer element, and adding a dynamic memory mark for the dynamic pointer element; when the ASN file is converted into a C / C + + library file, converting the dynamic pointer element to generate a pointer data structure; during encoding and decoding, the dynamic memory is allocated for the pointer data structure according to the dynamic memory mark, the C / C + + library file generated by the ASN file is fully automatically optimized, the structural body array is converted into the pointer data structure, the memory space of only one pointer can be allocated for the pointer data structure, and compared with the allocation of the fixed memory space, the occupation of the static memory is greatly reduced; the problems that the data structure in the C / C + + code generated by the ASN is redundant and a large amount of memory is occupied are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data communication and software engineering, and in particular to a memory management method, device, electronic device and computer storage medium. Background Art

[0002] ASN.1 (Abstract Syntax Notation One) is an interface description language widely used in communication protocols (such as 3GPP). ASN.1 defines a set of rules that can convert data structures into a standard format to achieve cross-platform data encoding and decoding.

[0003] In traditional implementations, when ASN.1 is directly converted into C / C++ code, a large number of redundant structure arrays are easily generated. When using structure arrays, the compiler will allocate a fixed size of memory for the entire structure array, which means that regardless of whether all the elements in the array will be used in the end, the system will allocate a fixed memory space for the entire array, taking up a large amount of memory.

[0004] With respect to the above-mentioned problems existing in the related technologies, no effective solutions have been found so far. Summary of the invention

[0005] The present application provides a memory management method, device, electronic device and computer storage medium to solve the above-mentioned technical problems existing in the related technology.

[0006] According to an embodiment of the present application, a memory management method is provided, comprising: obtaining an abstract syntax notation (ASN) file, detecting static structure array elements in the ASN file; replacing the static structure array elements with dynamic pointer elements, and adding a dynamic memory flag to the dynamic pointer elements; when converting the ASN file into a C / C++ library file, converting the dynamic pointer elements to generate a pointer data structure; and performing dynamic memory management on the pointer data structure according to the dynamic memory flag.

[0007] According to another embodiment of the present application, a memory management device is provided, including: a parsing module, used to obtain an abstract syntax notation ASN file, and detect static structure array elements in the ASN file; a replacement module, used to replace the static structure array elements with dynamic pointer elements, and add a dynamic memory flag to the dynamic pointer elements; a conversion module, used to convert the dynamic pointer elements to generate a pointer data structure when converting the ASN file into a C / C++ library file; and a management module, used to perform dynamic memory management on the pointer data structure according to the dynamic memory flag.

[0008] Optionally, the management module also includes a decoding unit, which is used to obtain the memory space required for the pointer data structure based on the dynamic memory flag during decoding; determine whether the memory space is less than or equal to the maximum memory space that can be allocated; if the memory space is less than or equal to the maximum memory space, allocate dynamic memory to the pointer data structure and store the corresponding pointer in the main structure.

[0009] Optionally, the management module also includes an encoding unit, which is used to, during encoding, mark the pointer data structure according to the dynamic memory flag and indicate that the corresponding memory needs to be released after encoding is completed; obtain the pointer address of the pointer data structure; detect whether the pointer address recorded in the record list reaches the storage upper limit; if the pointer address recorded in the record list does not reach the storage upper limit, add the pointer address to the record list; after encoding is completed, release the corresponding memory address according to the record list.

[0010] Optionally, the management module also includes an allocation unit, which is used to obtain a dynamic data list generated after the ASN file is converted into a C / C++ library file, wherein the dynamic data list includes the pointer data structure; identify the nested hierarchical structure of the dynamic data list; and allocate memory for dynamic data of different levels according to the nested hierarchical structure.

[0011] Optionally, the allocation unit also includes an allocation sub-unit, which is used to allocate memory to the inner layers layer by layer starting from the outer structure of the nested hierarchical structure; for each level, the following steps are performed: first allocate the memory required for the current level, then allocate the memory required for the next nested level of the current level, and use a pointer array to record the memory address of each level.

[0012] Optionally, the management module also includes a detection unit, which is used to traverse the dynamic array context list to find the encoding row number that matches the target nesting level where the pointer data structure is located, and the dynamic array context list is used to record the encoding row number and the corresponding number of elements of each nesting level; if a matching encoding row number is found, the number of elements of the target nesting level is detected; a release unit, which is used to release the pointer corresponding to the pointer data structure if it is detected that the number of elements of the target nesting level has dropped to zero, and adjust the structure of the dynamic array context list to remove the corresponding level information; an update unit, which is used to add new level information to the dynamic array context list if no matching encoding row number is found and the current number of nesting levels is less than a maximum threshold, and record the initial number of elements of the new level.

[0013] Optionally, the memory management device also includes an acquisition module for acquiring a specified information element; a judgment module for judging whether the specified information element is an optional element; a release module for setting the specified information element to a null value or an invalid value if the specified information element is an optional element; and releasing the memory space occupied by the specified information element.

[0014] According to another embodiment of the present application, a computer storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned device embodiments when running.

[0015] According to another embodiment of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein: the memory is used to store computer programs; the processor is used to execute the steps in the above method by running the program stored in the memory.

[0016] The electronic device provided in the embodiment of the present application may specifically be a module capable of realizing a communication function or a terminal device including the module, etc. The terminal device may be a mobile terminal or a smart terminal. The mobile terminal may specifically be at least one of a mobile phone, a tablet computer, a laptop computer, etc.; the smart terminal may specifically be a terminal including a wireless communication module such as a smart car, a smart watch, a shared bicycle, a smart cabinet, etc.; the module may specifically be a wireless communication module, such as any one of a 2G communication module, a 3G communication module, a 4G communication module, a 5G communication module, and a NB-IOT communication module.

[0017] According to yet another embodiment of the present application, a computer program product comprising instructions is also provided, which enables the computer to execute the steps in the above method when the computer program product is executed on the computer.

[0018] The embodiment of the present application obtains the abstract syntax notation ASN file, detects the static structure array elements in the ASN file; replaces the static structure array elements with dynamic pointer elements, and adds a dynamic memory flag to the dynamic pointer elements; when converting the ASN file to a C / C++ library file, converts the dynamic pointer elements to generate a pointer data structure; allocates dynamic memory to the pointer data structure according to the dynamic memory flag during encoding and decoding, fully automatically optimizes the C / C++ library file generated by the ASN file, converts the structure array to a pointer data structure, and only allocates memory space for one pointer for the pointer data structure, which greatly reduces the static memory usage compared to allocating a fixed memory space. The problem of redundant data structures in the C / C++ code generated by ASN.1 and large amounts of static and dynamic memory usage is solved. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0020] Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present application;

[0021] Figure 2 is a flow chart of a memory management method according to an embodiment of the present application;

[0022] Figure 3 It is a flowchart of custom memory management in an embodiment of the present application;

[0023] Figure 4 It is a structural block diagram of a memory management device according to an embodiment of the present application. DETAILED DESCRIPTION

[0024] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0026] Example 1

[0027] The method embodiment provided in the first embodiment of the present application can be executed in a mobile phone, a computer, a tablet or a similar computing device. Taking running on a computer as an example, Figure 1 is a hardware structure block diagram of a computer in an embodiment of the present application. Figure 1 As shown, the computer may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the computer may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0028] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to a memory management method in an embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0029] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0030] In this embodiment, a memory management method is provided. Figure 2 is a flowchart of a memory management method according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:

[0031] Step S10, obtaining an Abstract Syntax Notation ASN file, and detecting static structure array elements in the ASN file;

[0032] Step S20, replacing the static structure array element with a dynamic pointer element, and adding a dynamic memory flag to the dynamic pointer element;

[0033] Step S30, when converting the ASN file into a C / C++ library file, converting the dynamic pointer element to generate a pointer data structure;

[0034] Step S40: Perform dynamic memory management on the pointer data structure according to the dynamic memory flag.

[0035] In 3GPP, when the static structure array element SEQUENCE (SIZE OF (…)) in the ASN file is converted to a C / C++ library, a structure array will be generated. This type of structure array will occupy a large amount of memory. During the operation of the product, the huge structure array puts a lot of pressure on the chip heap memory. With the continuous upgrade of the 5G NR and 4G EUTRA protocols, the corresponding data structure memory will become larger and larger, which means more memory management requirements. In this embodiment, the static structure array element in the ASN file is detected, and the static structure array element in the ASN file is replaced with a dynamic pointer element DYN_SEQUENCE (SIZE OF (…)), wherein the dynamic pointer element is used to indicate that when the ASN file is converted to a C / C++ library file, the element needs to generate a pointer type data structure, and a dynamic memory flag (dynamic Flag) is added at the end of the replaced line. When the ASN file is converted to a C / C++ library file, it is detected whether the element has a dynamic Flag identifier, and a pointer data structure is generated for elements with dynamicFlag, and a normal array structure is generated for ordinary elements. Convert the structure array to a pointer, and allocate dynamic memory for the pointer data structure during encoding and decoding, so that only one pointer's memory space can be allocated, greatly reducing static memory usage, and using pointers can only allocate memory for elements that are actually needed, avoiding memory waste. Using pointers also allows for more flexible organization of memory layout. For example, all structures can be stored continuously in memory, thereby improving cache efficiency. Using pointers can make the code more modular, and the responsibility for memory management can be easily assigned to specific functions or modules, rather than considering the limitations of fixed-size arrays throughout the program.

[0036] In this embodiment, SEQUENCE refers to a composite data type used to represent an ordered set of information elements (IE). It contains zero or more predefined sub-information elements. The sub-information elements can be different data types, including but not limited to integers, enumerations, bit strings, octet strings, other SEQUENCEs or CHOICEs, etc. The sub-elements are arranged in a predefined order, and the position of each sub-element in the SEQUENCE is fixed. It can contain optional (OPTIONAL) sub-elements, which can be omitted under certain conditions. SEQUENCE (SIZE OF (...)) is a special SEQUENCE type used to represent an ordered set of elements of the same type with a variable number of elements. The elements it contains are of the same type and the number is variable. The SIZEOF (...) part defines the constraints on the number of elements in the set, which can be a fixed value, a range of values, or references to other parameters. When used for encoding, the actual number of elements will be encoded into the message, and the decoding end can dynamically allocate memory based on this. Supports empty sets (when the minimum size is 0) to a predefined maximum size.

[0037] This embodiment obtains the abstract syntax notation ASN file, detects the static structure array elements in the ASN file; replaces the static structure array elements with dynamic pointer elements, and adds dynamic memory flags to the dynamic pointer elements; when converting the ASN file to a C / C++ library file, converts the dynamic pointer elements to generate a pointer data structure; allocates dynamic memory to the pointer data structure according to the dynamic memory flag during encoding and decoding, fully automatically optimizes the C / C++ library file generated by the ASN file, converts the structure array to a pointer data structure, and only allocates memory space for one pointer for the pointer data structure, which greatly reduces the static memory usage compared to allocating fixed memory space. This solves the problem of redundant data structures in the C / C++ code generated by ASN.1, which occupies a large amount of static and dynamic memory.

[0038] In one implementation of this embodiment, performing dynamic memory management on the pointer data structure according to the dynamic memory flag includes:

[0039] A41, during decoding, obtaining the memory space required by the pointer data structure based on the dynamic memory flag;

[0040] A42, determining whether the memory space is less than or equal to the maximum memory space that can be allocated;

[0041] A43, if the memory space is less than or equal to the maximum memory space, dynamic memory is allocated to the pointer data structure, and the corresponding pointer is stored in the main structure.

[0042] In this embodiment, it is detected whether the current operation is a decoding operation. If it is a decoding operation, the following memory management is performed during decoding to obtain the memory space required by the pointer data structure. In order to prevent the allocation of too much memory, thereby avoiding potential memory overflow or allocation failure, it is determined whether the memory space is less than or equal to the maximum memory space allowed to be allocated. If the memory space is less than or equal to the maximum memory space that can be allocated, sufficient dynamic memory is allocated for the pointer data structure. After the memory allocation is successful, the allocated memory address is located to the correct position through pointer operations and the offset in the structure, and a pointer to this memory is stored in the corresponding field of the main structure so that the corresponding data can be accessed later through the pointer.

[0043] Correctly allocate memory during decoding and record the memory addresses that need to be released during encoding to avoid memory leaks that affect system performance.

[0044] In another implementation of this embodiment, performing dynamic memory management on the pointer data structure according to the dynamic memory flag includes:

[0045] B41, during encoding, marking the pointer data structure according to the dynamic memory flag that the corresponding memory needs to be released after the encoding is completed;

[0046] B42, obtaining the pointer address of the pointer data structure;

[0047] B43, detects whether the pointer address of the record in the record list reaches the storage upper limit;

[0048] B44, if the pointer address recorded in the record list has not reached the storage upper limit, adding the pointer address to the record list;

[0049] B45, after the encoding is completed, the corresponding memory address is released according to the record list.

[0050] In this embodiment, it is detected whether the current operation is an encoding operation. If it is an encoding operation, the following memory management is performed during encoding: whether the pointer data structure carries a dynamic memory flag. If the pointer data structure carries a dynamic memory flag, it indicates that the pointer data structure needs to release the corresponding memory after the encoding is completed. The pointer address of the pointer data structure is obtained, and it is detected whether the pointer address recorded in the record list reaches the storage upper limit. If the pointer address recorded in the record list does not reach the storage upper limit, the pointer address is added to the record list, and the pointer to be released is recorded in the record list. After the encoding is completed, the memory address corresponding to the pointer is tracked and released according to the record list.

[0051] This embodiment manages dynamically allocated memory addresses during the ASN encoding process. By obtaining the memory address of the data to be encoded and determining whether the memory address needs to be released after the encoding is completed, if necessary, the address is stored in a list for subsequent processing. This can prevent memory leaks and ensure that resources are released correctly.

[0052] In another implementation of this embodiment, performing dynamic memory management on the pointer data structure according to the dynamic memory flag includes:

[0053] C41, obtaining a dynamic data list generated after the ASN file is converted into a C / C++ library file, wherein the dynamic data list includes the pointer data structure;

[0054] C42, identifying the nested hierarchical structure of the dynamic data list;

[0055] C43, allocating memory for dynamic data at different levels according to the nested hierarchical structure.

[0056] In this embodiment, the dynamic data list is a data structure set generated after the ASN specification is converted into C / C++ code, and the data structure includes data structures of variable length elements such as DYN_SEQUENCE(SIZE OF(...)) in this embodiment. These structures will be converted into complex data types containing pointers to support dynamic memory allocation.

[0057] Analyze and identify the nested hierarchical structure of the dynamic data list. In the memory allocation process, the identified hierarchical relationship is used as an important reference factor, and the corresponding memory management strategy is adopted according to the characteristics of different levels. Among them, the nested hierarchical structure is a multi-layer nested relationship contained in the dynamic data list, and its characteristics include but are not limited to: hierarchical depth (indicates the maximum depth of nesting, and sets the threshold of the maximum number of nested dynamic items according to the 3GPP protocol content, which is used to limit the depth of the nested hierarchy and optimize the memory size), element type of each layer (including basic data type or pointer data type), number of elements of each layer (fixed number or variable number) and memory dependency (memory association between the upper structure and the lower structure). According to the characteristics of the nested hierarchical structure, memory is allocated for dynamic data structures of different levels.

[0058] When performing memory management of dynamic data lists, the hierarchical relationship of the dynamic data lists is fully considered and utilized, which can significantly improve memory utilization efficiency while ensuring the stability of memory management. It is particularly suitable for processing complex ASN.1 nested data structures.

[0059] Optionally, according to the nested hierarchical structure, memory allocation for dynamic data structures at different levels includes: starting from the outer structure of the nested hierarchical structure, allocating memory to the inner layers layer by layer; for each level, performing the following steps: first allocating the memory required for the current level, then allocating the memory required for the next nested level of the current level, and using a pointer array to record the memory address of each level.

[0060] Starting from the outermost layer of the nested hierarchical structure, the necessary memory space is first allocated for it. After the memory allocation of the outer structure is completed, it is advanced inward layer by layer to allocate the required memory for each inner structure. In this process, it is ensured that the memory allocation of each layer is based on the memory allocation result of its previous layer, thereby maintaining the integrity of the nested hierarchical structure. For the current layer, the required memory space is first allocated to store the elements or substructures of the current layer. Then, according to the nesting relationship of the current layer, memory is allocated to the next layer. This step ensures that each layer can obtain sufficient memory resources to support the storage of its internal elements or substructures. In order to facilitate subsequent access and release operations, a pointer array is used to record the memory address of each layer, so that the memory space of a certain layer can be quickly located when needed, thereby improving the efficiency and accuracy of memory management, and setting a threshold for the maximum number of nested dynamic items according to the 3GPP protocol content to limit the depth of the nested layer and optimize the memory size.

[0061] This implementation adopts a top-down memory allocation strategy for nested hierarchical structures during the encoding and decoding process, effectively managing complex pointer relationships, ensuring safe allocation and release of memory, and avoiding memory errors caused by repeated release.

[0062] In this embodiment, after memory is allocated for dynamic data structures of different levels according to the nested hierarchical structure, the method further includes: traversing the dynamic array context list to find the encoding row number that matches the target nested level where the pointer data structure is located, the dynamic array context list being used to record the encoding row number and the corresponding number of elements of each nested level; if a matching encoding row number is found, the number of elements of the target nested level is detected; if it is detected that the number of elements of the target nested level drops to zero, the pointer corresponding to the pointer data structure is released, and the structure of the dynamic array context list is adjusted to remove the corresponding level information; if no matching encoding row number is found and the current number of nested levels is less than the maximum threshold, the new level information is added to the dynamic array context list, and the initial number of elements of the new level is recorded.

[0063] Memory is allocated for dynamic data structures of different levels, which may be nested within each other to form a multi-level structure. Detect the number of elements at the target nesting level where the pointer data structure is located, specifically including: traversing the dynamic array context list, finding the encoding line number in the dynamic array context list that matches the target nesting level, and if a match is found, updating the number of elements of the item. Determine whether the pointer needs to be released based on the detection result of the number of elements, specifically including: if it is detected that the number of elements at the target nesting level where the pointer data structure is located has dropped to zero, release the pointer corresponding to the pointer data structure; if the number of elements has dropped to zero, it is also necessary to adjust the structure of the dynamic array context list and remove the corresponding level information; if no match is found and the current number of nesting levels is less than the maximum threshold, add the new level information to the list and record its initial number of elements.

[0064] Through the implementation method of the present invention, the ASN.1 encoding and decoding module adapts to the generated C / C++ library file, and automatically releases all dynamically allocated memory after encoding and decoding, greatly reducing the risk of memory leaks.

[0065] Dynamic memory management of the pointer data structure according to the dynamic memory flag during encoding and decoding includes: during the encoding and decoding process, using pointers can more flexibly handle variable-length data. For example, in network communication, it may be necessary to serialize and deserialize data structures of different sizes. Using pointers can more easily handle this situation: when encoding, determine the number of elements to be encoded, and then write the elements one by one; when decoding, read the number of elements first, and then dynamically allocate memory for each element. Dynamic memory management is simplified, and variable-size data sets can be handled more flexibly.

[0066] Reference Figure 3 In another implementation of this embodiment, the method also includes: obtaining a specified information element; determining whether the specified information element is an optional element; if the specified information element is an optional element, setting the specified information element to a null value or an invalid value; and releasing the memory space occupied by the specified information element.

[0067] In this embodiment, the name of the IE (information element) specified by the user is obtained, and a regular expression or other string parsing method is used to check whether the specified IE name contains the OPTIONAL optional descriptor. The IE marked with the optional descriptor is an optional configuration item. If the specified IE carries the optional descriptor, the specified information element can be determined to be an optional element, and the specified information element is set to NULL. NULL represents a null value or an invalid value, which is used to indicate that the IE does not exist or is not used, and the memory space occupied by the specified information element is released, and the processing result is returned. If the specified information element does not carry the optional descriptor, it means that the specified information element is not an optional element, and it is regarded as a mandatory item and must appear in the message. The deletion operation is not performed, and a prompt of "cannot be deleted" is returned.

[0068] This implementation manner can process the 3GPP information element (IE) specified by the user, and delete the memory space occupied by the OPTIONAL (optional value) IE according to the user's required content while ensuring normal encoding and decoding.

[0069] This embodiment provides an application example process of a memory management method, including: preprocessing stage: run a dedicated Python script to process 3GPP ASN files. The script accepts two input parameters: the original ASN file (such as "38331.asn") and an optional IE list file (such as "removeIeList.json"). After the script is executed, an optimized ASN.1C / C++ library file is generated. Running stage: In the target system, the encoding and decoding interface is called. The "asn_engine(...)" function is called internally in this interface to achieve unified management of all dynamic memory. Through the collaborative optimization of preprocessing and runtime, the memory utilization efficiency in the ASN.1 encoding and decoding process is significantly improved, memory fragmentation is reduced, and the risk of memory leakage is reduced, which is suitable for resource-constrained embedded systems.

[0070] This has been fully verified by optimizing the terminal device capability (UE-EUTRA-Capability) structure in the 3GPP specification. The specific data analysis is as follows:

[0071] Before optimization: The C / C++ library file generated by UE-EUTRA-Capability contains dozens of structure arrays. According to the statistics of the general IDE VSCode, the total space occupied by the UE-EUTRA-Capability structure is 61,562,416 bytes. Since UE-EUTRA-Capability must create at least one instance, the size of the generated binary file is not less than 50MB.

[0072] Effect after optimization: All structure arrays are replaced with pointers, each of which occupies 8 bytes. The total space occupied by the optimized UE-EUTRA-Capability structure is reduced to 10,920 bytes. The space occupied is reduced by 99.98%, significantly reducing static memory requirements.

[0073] Dynamic memory management: When the system is running, DYN_SEQUENCE dynamically allocates heap memory according to actual needs, which requires about 100,000 bytes. This dynamic memory is automatically released by asn_engine.c after encoding. No memory leaks were found through Valgrind tool monitoring, which proves the reliability of the memory management mechanism.

[0074] Functional verification: The UPER (Unaligned Packed Encoding Rules) code stream output by the target system was successfully decoded by the third-party codec software Pycrate. The decoded configuration content is completely consistent with the test input, verifying that significant optimization is achieved while ensuring functional integrity.

[0075] This embodiment significantly reduces static memory usage while ensuring system stability and reliability through an efficient dynamic memory management mechanism, while also ensuring compatibility with existing standards. This optimization has important practical value for resource-constrained embedded systems.

[0076] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0077] Example 2

[0078] In this embodiment, a memory management device is also provided to implement the above-mentioned embodiments and preferred implementation modes, which have been described and will not be repeated here. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0079] Figure 4is a structural block diagram of a memory management device according to an embodiment of the present application, such as Figure 4 As shown, the device comprises:

[0080] The parsing module 41 is used to obtain an abstract syntax notation ASN file and detect static structure array elements in the ASN file;

[0081] A replacement module 42, used to replace the static structure array element with a dynamic pointer element, and add a dynamic memory flag to the dynamic pointer element;

[0082] A conversion module 43, used for converting the dynamic pointer element to generate a pointer data structure when converting the ASN file into a C / C++ library file;

[0083] The management module 44 is used to perform dynamic memory management on the pointer data structure according to the dynamic memory flag.

[0084] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0085] Example 3

[0086] An embodiment of the present application further provides a computer storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0087] Optionally, in this embodiment, the computer storage medium may be configured to store a computer program for performing the following steps:

[0088] S1, obtaining an abstract syntax notation ASN file, and detecting static structure array elements in the ASN file;

[0089] S2, replacing the static structure array element with a dynamic pointer element, and adding a dynamic memory flag to the dynamic pointer element;

[0090] S3, when converting the ASN file into a C / C++ library file, converting the dynamic pointer element to generate a pointer data structure;

[0091] S4, performing dynamic memory management on the pointer data structure according to the dynamic memory flag.

[0092] Optionally, in this embodiment, the above-mentioned computer storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0093] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0094] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0095] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:

[0096] S1, obtaining an abstract syntax notation ASN file, and detecting static structure array elements in the ASN file;

[0097] S2, replacing the static structure array element with a dynamic pointer element, and adding a dynamic memory flag to the dynamic pointer element;

[0098] S3, when converting the ASN file into a C / C++ library file, converting the dynamic pointer element to generate a pointer data structure;

[0099] S4, performing dynamic memory management on the pointer data structure according to the dynamic memory flag.

[0100] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0101] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0102] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0103] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0104] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0105] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0106] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially 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, and the computer software product is stored in a computer storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned computer storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or CD-ROM and other media that can store program codes.

[0107] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A memory management method, characterized in that: The method comprises: Obtain an Abstract Syntax Notation (ASN) file, and detect static structure array elements in the ASN file; Replacing the static structure array element with a dynamic pointer element, and adding a dynamic memory flag to the dynamic pointer element; When converting the ASN file into a C / C++ library file, converting the dynamic pointer element to generate a pointer data structure; Dynamic memory management is performed on the pointer data structure according to the dynamic memory flag.

2. The method according to claim 1, characterized in that Performing dynamic memory management on the pointer data structure according to the dynamic memory flag includes: During decoding, the memory space required by the pointer data structure is obtained based on the dynamic memory flag; Determine whether the memory space is less than or equal to the maximum memory space that can be allocated; If the memory space is less than or equal to the maximum memory space, dynamic memory is allocated for the pointer data structure, and the corresponding pointer is stored in the main structure.

3. The method according to claim 1, characterized in that Performing dynamic memory management on the pointer data structure according to the dynamic memory flag includes: During encoding, the pointer data structure is marked according to the dynamic memory flag and the corresponding memory needs to be released after the encoding is completed; Obtaining a pointer address of the pointer data structure; Check whether the pointer address of the record in the record list reaches the storage upper limit; If the pointer address recorded in the record list has not reached the storage upper limit, adding the pointer address to the record list; After the encoding is completed, the corresponding memory address is released according to the record list.

4. The method according to claim 1, characterized in that Performing dynamic memory management on the pointer data structure according to the dynamic memory flag includes: Obtain a dynamic data list generated after the ASN file is converted into a C / C++ library file, wherein the dynamic data list includes the pointer data structure; Identifying a nested hierarchical structure of the dynamic data list; According to the nested hierarchical structure, memory is allocated to dynamic data at different levels.

5. The method according to claim 4, characterized in that According to the nested hierarchical structure, memory allocation for dynamic data structures at different levels includes: Starting from the outer structure of the nested hierarchical structure, memory is allocated to the inner layers layer by layer; For each level, the following steps are performed: first allocate the memory required for the current level, then allocate the memory required for the next nested level of the current level, and use a pointer array to record the memory address of each level.

6. The method according to claim 4, characterized in that After allocating memory for dynamic data structures at different levels according to the nested hierarchical structure, the method further includes: Traversing the dynamic array context list to find the encoding line number that matches the target nesting level where the pointer data structure is located, the dynamic array context list is used to record the encoding line number and the corresponding number of elements of each nesting level; If a matching encoding line number is found, the number of elements in the target nesting level is detected; If it is detected that the number of elements of the target nesting level drops to zero, the pointer corresponding to the pointer data structure is released, and the structure of the dynamic array context list is adjusted to remove the corresponding level information; If no matching encoding line number is found and the current number of nested levels is less than the maximum threshold, the new level information is added to the dynamic array context list and the initial number of elements of the new level is recorded.

7. The method according to claim 1, characterized in that The method further comprises: Get the specified information element; Determining whether the specified information element is an optional element; If the designated information element is an optional element, the designated information element is set to a null value or an invalid value; and the memory space occupied by the designated information element is released.

8. A memory management device, characterized in that: include: A parsing module, used for obtaining an abstract syntax notation ASN file and detecting static structure array elements in the ASN file; A replacement module, used to replace the static structure array elements with dynamic pointer elements, and add a dynamic memory flag to the dynamic pointer elements; A conversion module, used for converting the dynamic pointer element to generate a pointer data structure when converting the ASN file into a C / C++ library file; A management module is used to perform dynamic memory management on the pointer data structure according to the dynamic memory flag.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; wherein: Memory, used to store computer programs; A processor, configured to execute the memory management method according to any one of claims 1 to 7 by running a program stored in a memory.

10. A computer storage medium, characterized in that: The computer storage medium includes a stored program, wherein the program executes the memory management method according to any one of claims 1 to 7 when running.

Citation Information

Cited By

  • Memory information processing method of electric energy meter, electronic equipment and storage medium

    CN120909955A