Data processing method and apparatus, electronic device, and medium

By parsing and determining the type of the data structure, the creation of dynamic data types in a static language is realized, which solves the problem of low efficiency in dynamic memory allocation and data initialization in static languages ​​and supports the dynamic creation of multiple data types.

CN115951894BActive Publication Date: 2026-08-04APOLLO INTELLIGENT CONNECTIVITY (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
APOLLO INTELLIGENT CONNECTIVITY (BEIJING) TECH CO LTD
Filing Date
2022-12-16
Publication Date
2026-08-04

AI Technical Summary

Technical Problem

In statically typed languages, the need to dynamically create custom data types is often labor-intensive and inefficient. How to achieve dynamic memory allocation and data initialization during program execution becomes an important issue.

Method used

By parsing instance data with data structures, obtaining descriptive information, determining member types, and allocating an appropriate amount of memory based on the types for initialization, dynamic data types can be created.

Benefits of technology

The creation of dynamic data types is implemented in statically typed languages, which improves the efficiency and flexibility of memory allocation and supports the dynamic creation of various data types.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115951894B_ABST
    Figure CN115951894B_ABST
Patent Text Reader

Abstract

The present disclosure provides a data processing method and device, electronic equipment and medium, relating to the technical field of computer. The implementation scheme is: obtaining first data with a data structure, wherein the data structure has at least one member; parsing the first data to obtain description information corresponding to the data structure; determining the type of each member in the at least one member based on the description information; determining the size of the memory to be applied and applying the memory of the corresponding size based on the type of each member in the data structure; and initializing each member in the data structure in the applied memory based on the type of each member in the data structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and specifically to a data processing method, apparatus, electronic device, computer-readable storage medium, and computer program product. Background Technology

[0002] Computer programming languages ​​can be categorized into statically typed languages ​​and dynamically typed languages. Statically typed languages ​​determine the data types of variables at compile time, and their structure cannot be changed during runtime; these languages, such as C++ and C#, are deterministic before execution. This allows the compiler to determine the total memory required for the program's runtime. Dynamically typed languages ​​determine their data types and structures at runtime. Variables do not require type declarations before use; typically, the type of a variable is the type of the value assigned to it, and memory is allocated accordingly. The type and value of a variable are initialized at the moment of assignment and stored in the allocated memory, as seen in languages ​​like Python and Perl. However, in practical applications, there is often a need to dynamically create custom data types during program execution. Migrating projects between statically and dynamically typed languages ​​is typically labor-intensive and inefficient. Therefore, it is crucial to develop a method for dynamically allocating memory and initializing data in statically typed languages ​​during runtime to enable the creation of dynamic data types.

[0003] The methods described in this section are not necessarily methods that had been previously conceived or adopted. Unless otherwise specified, no method described in this section should be assumed to be prior art simply because it is included in this section. Similarly, unless otherwise specified, the issues mentioned in this section should not be considered to be accepted in any prior art. Summary of the Invention

[0004] This disclosure provides a data processing method, apparatus, electronic device, computer-readable storage medium, and computer program product.

[0005] According to one aspect of this disclosure, a data processing method is provided, comprising: acquiring first data having a data structure, wherein the data structure has at least one member; parsing the first data to obtain description information corresponding to the data structure; determining the type of each member among the at least one member based on the description information; determining the size of memory to be requested based on the type of each member in the data structure and requesting memory of the corresponding size; and initializing each member in the data structure in the requested memory based on the type of each member in the data structure.

[0006] According to another aspect of this disclosure, a data processing apparatus is provided, comprising: an acquisition module configured to acquire first data having a data structure, wherein the data structure has at least one member; a parsing module configured to parse the first data to obtain description information corresponding to the data structure; a first determining module configured to determine the type of each member among the at least one member based on the description information; a second determining module configured to determine the size of memory to be requested and request memory of the corresponding size based on the type of each member in the data structure; and a first initialization module configured to initialize each member in the data structure in the requested memory based on the type of each member in the data structure.

[0007] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the methods described above.

[0008] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause the computer to perform the above-described method.

[0009] According to another aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the above-described method.

[0010] According to one or more embodiments of this disclosure, a data processing method is provided, which parses instance data with a data structure to obtain description information of the data structure, determines the type of each member in the data structure based on the description information, determines the required memory size based on the member type, and performs memory allocation and member initialization, so as to realize the creation of dynamic data types in a static language.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0012] The accompanying drawings exemplify embodiments and form part of the specification, serving together with the textual description to explain exemplary implementations of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0013] Figure 1 This is a schematic diagram illustrating an example system in which various methods described herein may be implemented according to exemplary embodiments;

[0014] Figure 2 A flowchart of a data processing method according to an embodiment of the present disclosure is shown;

[0015] Figure 3 A flowchart of a portion of a data processing method according to an embodiment of the present disclosure is shown;

[0016] Figure 4 A structural block diagram of a data processing apparatus according to embodiments of the present disclosure is shown; and

[0017] Figure 5 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation

[0018] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0019] In this disclosure, unless otherwise stated, the use of terms such as "first," "second," etc., to describe various elements is not intended to limit the positional, temporal, or importance relationships of these elements; such terms are merely used to distinguish one element from another. In some examples, the first element and the second element may refer to the same instance of that element, while in other cases, based on the context, they may refer to different instances.

[0020] The terminology used in the description of the various examples described in this disclosure is for the purpose of describing particular examples only and is not intended to be limiting. Unless the context explicitly indicates otherwise, an element may be one or more unless the number of elements is specifically limited. Furthermore, the term "and / or" as used in this disclosure covers any one of the listed items and all possible combinations thereof.

[0021] In related technologies, in static languages ​​such as C++, the data type must be declared before using a variable, so that the data type of the variable can be determined at compile time and its structure cannot be changed during runtime. Therefore, it is impossible to dynamically create data types during program execution.

[0022] To address the aforementioned issues, this disclosure provides a data processing method that parses instance data with a data structure to obtain the data structure's description information, determines the type of each member in the data structure based on the description information, determines the required memory size based on the member type, and allocates memory and initializes the members, thereby enabling the creation of dynamic data types in a statically typed language.

[0023] The embodiments of this disclosure will now be described in detail with reference to the accompanying drawings.

[0024] Figure 1 A schematic diagram of an exemplary system 100 in which the various methods and apparatus described herein can be implemented according to embodiments of this disclosure is shown. Reference Figure 1 The system 100 includes one or more client devices 101, 102, 103, 104, 105 and 106, a server 120, and one or more communication networks 110 coupling the one or more client devices to the server 120. The client devices 101, 102, 103, 104, 105 and 106 can be configured to execute one or more applications.

[0025] In embodiments of this disclosure, server 120 may run one or more services or software applications that enable the execution of data processing methods.

[0026] In some embodiments, server 120 may also provide other services or software applications that may include non-virtual and virtual environments. In some embodiments, these services may be provided as web-based services or cloud services, such as to users of client devices 101, 102, 103, 104, 105 and / or 106 under a Software as a Service (SaaS) model.

[0027] exist Figure 1 In the configuration shown, server 120 may include one or more components that implement the functions performed by server 120. These components may include software components, hardware components, or combinations thereof that can be executed by one or more processors. Users operating client devices 101, 102, 103, 104, 105, and / or 106 can sequentially interact with server 120 using one or more client applications to utilize the services provided by these components. It should be understood that various different system configurations are possible and may differ from system 100. Therefore, Figure 1 This is an example of a system used to implement the methods described herein, and is not intended to be limiting.

[0028] Users can use client devices 101, 102, 103, 104, 105, and / or 106 to execute data processing methods. The client devices can provide an interface that allows users to interact with the client devices. The client devices can also output information to the user through this interface. Although... Figure 1 Only six client devices are described, but those skilled in the art will understand that this disclosure can support any number of client devices.

[0029] Client devices 101, 102, 103, 104, 105, and / or 106 may include various types of computer devices, such as portable handheld devices, general-purpose computers (such as personal computers and laptops), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, gaming systems, thin clients, various messaging devices, sensors, or other sensing devices. These computer devices can run various types and versions of software applications and operating systems, such as Microsoft Windows, Apple iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as Google Chrome OS); or include various mobile operating systems, such as Microsoft Windows Mobile OS, iOS, Windows Phone, and Android. Portable handheld devices may include cellular phones, smartphones, tablets, personal digital assistants (PDAs), etc. Wearable devices may include head-mounted displays (such as smart glasses) and other devices. Gaming systems may include various handheld gaming devices, internet-enabled gaming devices, etc. Client devices are capable of executing various applications, such as various internet-related applications, communication applications (such as email applications), short message service (SMS) applications, and can use various communication protocols.

[0030] Network 110 can be any type of network well known to those skilled in the art, and can use any of a variety of available protocols (including but not limited to TCP / IP, SNA, IPX, etc.) to support data communication. By way of example only, one or more networks 110 can be a local area network (LAN), an Ethernet-based network, a token ring network, a wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, a public switched telephone network (PSTN), an infrared network, a wireless network (e.g., Bluetooth, WIFI), and / or any combination of these and / or other networks.

[0031] Server 120 may include one or more general-purpose computers, special-purpose server computers (e.g., PC (personal computer) servers, UNIX servers, mid-range servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and / or combination. Server 120 may include one or more virtual machines running a virtual operating system, or other computing architectures involving virtualization (e.g., one or more flexible pools of logical storage devices that can be virtualized to maintain virtual storage devices for servers). In various embodiments, server 120 may run one or more services or software applications that provide the functionality described below.

[0032] The computing unit in server 120 can run one or more operating systems, including any of the aforementioned operating systems and any commercially available server operating system. Server 120 can also run any of a variety of additional server applications and / or middleware applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, etc.

[0033] In some implementations, server 120 may include one or more applications to analyze and merge data feeds and / or event updates received from users of client devices 101, 102, 103, 104, 105, and 106. Server 120 may also include one or more applications to display data feeds and / or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and 106.

[0034] In some implementations, server 120 can be a server for a distributed system or a server integrated with blockchain. Server 120 can also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. A cloud server is a host product in the cloud computing service system, designed to address the shortcomings of traditional physical hosts and Virtual Private Server (VPS) services, such as high management difficulty and weak business scalability.

[0035] System 100 may also include one or more databases 130. In some embodiments, these databases may be used to store data and other information. For example, one or more of the databases 130 may be used to store information such as audio files and video files. Databases 130 may reside in various locations. For example, a database used by server 120 may be local to server 120, or it may be located away from server 120 and may communicate with server 120 via a network-based or dedicated connection. Databases 130 may be of different types. In some embodiments, the database used by server 120 may be, for example, a relational database. One or more of these databases may store, update, and retrieve data from and from the databases in response to commands.

[0036] In some embodiments, one or more of the databases 130 may also be used by an application to store application data. The databases used by the application may be of different types, such as key-value stores, object stores, or regular stores supported by a file system.

[0037] Figure 1 The system 100 can be configured and operated in various ways to enable the application of the various methods and apparatus described in this disclosure.

[0038] Figure 2 A flowchart of a data processing method according to an embodiment of the present disclosure is shown.

[0039] like Figure 2 As shown, the data processing method 200 includes:

[0040] Step S201: Obtain first data with a data structure, wherein the data structure has at least one member;

[0041] Step S202: Parse the first data to obtain the description information corresponding to the data structure;

[0042] Step S203: Based on the description information, determine the type of each member among the at least one member;

[0043] Step S204: Based on the type of each member in the data structure, determine the size of the memory to be requested and request the corresponding size of memory; and

[0044] Step S205: Based on the type of each member in the data structure, initialize each member in the data structure in the allocated memory.

[0045] In one example, the first data obtained in step S201 is IDL data, which defines the data structure using Interface Description Language (IDL), meaning that the data structure is stored in the IDL data.

[0046] The data structure in IDL data can be at least one of the following: struct, union, and enum. Taking union as an example, a union type data can typically include multiple members of different types, such as int8, int16, and char members. The memory size occupied by each member is determined by its type; for example, an int8 member occupies 1 byte, and an int16 member occupies 2 bytes.

[0047] In step S202, a syntax parsing tool can be used to parse the IDL data to obtain the parsed data, namely the descriptor corresponding to the data structure.

[0048] It is understood that the Descriptor contains information about each member of the data structure. Therefore, in step S203, the type of each member in the data structure can be determined according to the Descriptor, and memory can be allocated and each member initialized accordingly based on the type of each member in the data structure.

[0049] The creation of a dynamic data type can specifically include two steps: determining the total amount of memory required and allocating memory of the corresponding size; and initializing the data in the allocated memory, thereby completing the creation of the dynamic data type. In data processing method 200, step S203 determines the type of each member in the data structure, and step S204 determines the size of the memory to be allocated based on the type of each member and allocates memory of the corresponding size, thus realizing the first step in the creation of the dynamic data type, namely, determining the total amount of memory required and allocating memory of the corresponding size; in step S205, based on the type of each member, the initialization method for each member is determined and each member is initialized in the allocated memory, thus realizing the second step in the creation of the dynamic data type, namely, initializing the data in the allocated memory, thereby realizing the creation of the dynamic data type.

[0050] Therefore, by parsing instance data with data structures to obtain the description information of the data structure, and determining the type of each member in the data structure based on the description information, memory is allocated and members are initialized according to the member type, so as to realize the creation of dynamic data types in a static language.

[0051] For example, a data structure may include various types of members to support the dynamic creation of different types of data. In one example, the supported data types include, but are not limited to: int8, int16, int32, int64, unit8, unit16, unit32, unit64, float, double, bool, char, wchar, string, wstring, vector, struct, union, and enum.

[0052] In one example, the parsed descriptor information can be stored in a database called DescriptorDatabase, and DescriptorPool can be used to manage the descriptors in DescriptorDatabase, enabling the addition and querying of descriptors.

[0053] Figure 3 A flowchart of a portion of a data processing method according to an embodiment of the present disclosure is shown.

[0054] like Figure 3 As shown, step S204 includes:

[0055] Step S301: Based on the type of each member in the data structure, determine the memory size required to store each member;

[0056] Step S302: Based on the type of each member in the data structure, determine the memory size required for memory alignment when storing each member; and

[0057] Step S303: Determine the size of the memory to be requested based on the memory size required to store each member and the memory size required for memory alignment.

[0058] As mentioned above, after determining the type of each member, the memory size required to store each member can be determined. For example, storing an int8 member requires 1 byte, storing an int16 member requires 2 bytes, etc. Thus, the memory size required to store each member can be determined in step S301.

[0059] Understandably, when storing data, memory alignment is usually considered to facilitate memory management and reduce the number of read operations during data retrieval. Step S302 is used to determine the amount of free memory needed to achieve memory alignment itself.

[0060] Therefore, after determining the memory size required to store each member and the memory size required for memory alignment, step S303 can determine the size of the memory to be requested based on the sum of the two.

[0061] According to some embodiments, the data processing method 200 further includes: determining whether the data structure has a parent class; and in response to the data structure having a parent class, determining the memory size required by the parent class corresponding to the data structure. Step S303 includes: determining the size of the memory to be requested based on the memory size required to store each member, the memory size required for memory alignment, and the memory size required by the parent class corresponding to the data structure.

[0062] When a data structure has a parent class, it is necessary to first calculate the memory size occupied by the parent class so that the parent class can be stored accordingly. Specifically, the process of calculating the memory size occupied by the parent class is similar to the process of calculating the memory size required by the data structure. It is necessary to determine the type of each member in the parent class and the memory size required to store each type member, and calculate the memory size required for memory alignment. The sum of the two is the memory size required by the parent class.

[0063] When a data structure has a parent class, the amount of memory to be requested is the sum of the memory required by the data structure itself and the memory required by the parent class, taking memory alignment into account.

[0064] According to some embodiments, step S205 includes: in response to determining that the data structure includes members of a first type, initializing the members of the first type to system default values ​​in the allocated memory, wherein the first type is one of an integer type and a floating-point type; and in response to determining that the data structure includes members of a second type, initializing the members of the second type in the allocated memory using pointers, wherein the second type is one of a string, a structure, and a union.

[0065] Understandably, the first type consists of basic numeric types, such as int, float, and double. When initializing a member of the first type, it is initialized to the system default value, which is typically 0.

[0066] For members of the second type, such as those of string, struct, and union, since their length cannot be determined before assignment (they could be strings with many characters, or structs or unions containing multiple members), pointers can be used to initialize them. In one example, a null pointer can be used to initialize a member of the second type, and upon receiving an assignment to that member, the pointer can be redirected to a memory address corresponding to the assigned value, thus achieving efficient memory utilization.

[0067] According to some embodiments, the data processing method 200 further includes: defining a target union with a target name, wherein the target union includes a plurality of members corresponding to a plurality of types, and wherein the plurality of members includes a member of an array type, and the target name is an element of the member of the array type. Step S205 further includes: in response to determining that the data structure includes a member of the array type, initializing the member of the array type in the allocated memory based on the target name of the target union.

[0068] The following is a specific example of a target union named UnknowType:

[0069]

[0070] As can be seen, the target union UnknowType includes multiple members corresponding to multiple types, including std::vector. <unknowtype>This array type has members, and these members use `UnknownType` as elements of the array, thus enabling nested arrays to support multidimensional arrays. Furthermore, this is achieved by defining the array type members as `std::vector`. <unknowtype>The *_vec_ptr class enables array type members to be treated like pointers, allowing the size of their memory allocation to be determined. This solves the problem of dynamic memory allocation, enabling the allocation of memory of a given size when the size of the memory to be allocated is determined.

[0071] It is understood that the above examples are merely illustrative of the supported member types, and the number and types of members in the target union can be specifically set as needed.

[0072] Therefore, after determining that the data structure includes array-type members, the array-type members are initialized using the target name of the target union, that is, the array-type members are replaced with vectors. <unknowtype>Therefore, regardless of the types of members included in the array type, it is universally applicable as a vector. <unknowtype>Because the `UnknowType` class's `Union` includes all supported types, during the creation and assignment of objects to members of an array, objects of the corresponding type can be created based on the type of the members in the array. This achieves the generalization of array representation and enables the use of `vector`. <unknowtype>The replacement of arrays enables nested arrays, thus supporting the creation of multidimensional arrays.

[0073] According to some embodiments, the data processing method 200 further includes: in response to the data structure having a parent class, initializing each member in the parent class before initializing each member in the data structure.

[0074] It is understandable that when a data structure has a parent class, the members of the parent class must be initialized before the members of the data structure are initialized, thus enabling the method to support class inheritance. The process of initializing the members of the parent class is similar to the process of initializing the members of the data structure, and will not be elaborated here.

[0075] According to some embodiments, the data processing method 200 further includes: in response to the completion of program execution based on the first data, performing deinitialization on all initialized members and releasing the allocated memory.

[0076] Understandably, after the program finishes running, the data can be restored by performing the reverse operation. At the same time, to avoid memory leaks, the allocated memory needs to be released.

[0077] According to another aspect of this disclosure, a data processing apparatus is provided. For example... Figure 4 As shown, the data processing device 400 includes: an acquisition module 401 configured to acquire first data having a data structure, wherein the data structure has at least one member; a parsing module 402 configured to parse the first data to obtain description information corresponding to the data structure; a first determination module 403 configured to determine the type of each member among the at least one member based on the description information; a second determination module 404 configured to determine the size of the memory to be requested and request memory of the corresponding size based on the type of each member in the data structure; and a first initialization module 405 configured to initialize each member in the data structure in the requested memory based on the type of each member in the data structure.

[0078] In one example, the first data acquired by module 401 is IDL data, which defines the data structure using Interface Description Language (IDL). That is, the data structure is stored in the IDL data.

[0079] The data structure in IDL data can be at least one of the following: struct, union, and enum. Taking union as an example, a union type data can typically include multiple members of different types, such as int8, int16, and char members. The memory size occupied by each member is determined by its type; for example, an int8 member occupies 1 byte, and an int16 member occupies 2 bytes.

[0080] The parsing module 402 can use a syntax parsing tool to parse the IDL data to obtain the parsed data, namely the descriptor corresponding to the data structure.

[0081] It is understandable that the Descriptor contains information about each member of the data structure, so the first determining module 403 can determine the type of each member of the data structure based on the Descriptor, and allocate memory and initialize each member accordingly based on the type of each member of the data structure.

[0082] The creation of a dynamic data type can specifically include two steps: determining the total amount of memory required and allocating memory of the corresponding size; and initializing the data in the allocated memory, thereby completing the creation of the dynamic data type. For the data processing device 400, the first determining module 403 determines the type of each member in the data structure, and the second determining module 404 determines the size of the memory to be allocated based on the type of each member and allocates memory of the corresponding size, thus realizing the first step in the creation of the dynamic data type, namely, determining the total amount of memory required and allocating memory of the corresponding size; the first initialization module 405 determines the initialization method for each member based on the type of each member and initializes each member in the allocated memory, thus realizing the second step in the creation of the dynamic data type, namely, initializing the data in the allocated memory. Therefore, the data processing device 400 realizes the creation of the dynamic data type.

[0083] Therefore, by parsing instance data with data structures to obtain the description information of the data structure, and determining the type of each member in the data structure based on the description information, memory is allocated and members are initialized according to the member type, so as to realize the creation of dynamic data types in a static language.

[0084] For example, a data structure may include various types of members to support the dynamic creation of different types of data. In one example, the supported data types include, but are not limited to: int8, int16, int32, int64, unit8, unit16, unit32, unit64, float, double, bool, char, wchar, string, wstring, vector, struct, union, and enum.

[0085] In one example, the parsing module 402 can store the parsed descriptor information in the database DescriptorDatabase, and use DescriptorPool to manage the descriptors in the DescriptorDatabase, so as to realize the addition and query of descriptors.

[0086] According to some embodiments, the second determining module 404 includes: a first determining unit configured to determine the memory size required to store each member based on the type of each member in the data structure; a second determining unit configured to determine the memory size required for memory alignment when storing each member based on the type of each member in the data structure; and a third determining unit configured to determine the size of the memory to be requested based on the memory size required to store each member and the memory size required for memory alignment.

[0087] As mentioned above, after the first determining module 403 determines the type of each member, the second determining module 404 can determine the memory size required to store each member. For example, storing an int8 member requires 1 byte, storing an int16 member requires 2 bytes, etc. Thus, the first determining unit can determine the memory size required to store each member.

[0088] Understandably, when storing data, memory alignment is typically considered to facilitate memory management and reduce the number of read operations. The second determining unit is used to determine the amount of free memory required to implement memory alignment itself.

[0089] Therefore, after determining the memory size required to store each member and the memory size required for memory alignment, the third determining unit can determine the size of the memory to be requested based on the sum of the two.

[0090] According to some embodiments, the data processing apparatus 400 further includes: a third determining module configured to determine whether the data structure has a parent class; and a fourth determining module configured to determine the memory size required by the parent class corresponding to the data structure in response to the data structure having a parent class. The third determining unit is further configured to determine the size of the memory to be requested based on the memory size required to store each member, the memory size required for memory alignment, and the memory size required by the parent class corresponding to the data structure.

[0091] When a data structure has a parent class, the memory size occupied by the parent class needs to be calculated first, so that the parent class can be stored accordingly. Specifically, the process of calculating the memory size occupied by the parent class is similar to the process of calculating the memory size required by the data structure. The fourth determining module needs to determine the type of each member in the parent class and the memory size required to store each type member, and calculate the memory size required for memory alignment. The sum of the two is the memory size required by the parent class.

[0092] When a data structure has a parent class, the amount of memory to be requested is the sum of the memory required by the data structure itself and the memory required by the parent class, taking memory alignment into account.

[0093] According to some embodiments, the first initialization module 405 includes: a first initialization unit configured to initialize members of the first type to system default values ​​in allocated memory in response to determining that the data structure includes members of the first type, wherein the first type is one of an integer type and a floating-point type; and a second initialization unit configured to initialize members of the second type in allocated memory using pointers in response to determining that the data structure includes members of the second type, wherein the second type is one of a string, a structure, and a union.

[0094] Understandably, the first type is a basic numeric type, such as int, float, and double. When the first initialization unit initializes a member of the first type, it initializes that member to the system default value, which is usually 0.

[0095] For members of the second type, such as those of type string, struct, and union, since the length of the member cannot be determined before assignment (it might be a string with many characters, or a struct or union containing multiple members), the second initialization unit can use a pointer to initialize the member of the second type. In one example, the second initialization unit can use a null pointer to initialize the member of the second type, and after receiving the assignment to the member of the second type, point the pointer to a memory address of the size corresponding to the assigned value, thus achieving reasonable use of memory.

[0096] According to some embodiments, the data processing apparatus 400 further includes: a definition module configured to define a target union having a target name, wherein the target union includes a plurality of members corresponding to a plurality of types, and wherein the plurality of members includes a member of an array type, and the target name is an element of the member of the array type. The first initialization module 405 further includes: a third initialization unit configured to initialize the member of the array type in the allocated memory based on the target name of the target union in response to determining that the data structure includes a member of the array type.

[0097] The following is a specific example of a target union named UnknowType defined by the definition module:

[0098]

[0099] As can be seen, the target union UnknowType includes multiple members corresponding to multiple types, including std::vector. <unknowtype>This array type has members, and these members use `UnknownType` as elements of the array, thus enabling nested arrays to support multidimensional arrays. Furthermore, this is achieved by defining the array type members as `std::vector`. <unknowtype>The *_vec_ptr parameter enables array type members to be configured to occupy memory in the same way as pointers, thus solving the problem of dynamic memory allocation. When the second determination module 404 determines the size of the memory to be requested, it can obtain the determined size of the memory and request the corresponding size of memory.

[0100] It is understood that the above examples are merely illustrative of the supported member types, and the number and types of members in the target union can be specifically set as needed.

[0101] Therefore, after determining that the data structure includes array-type members, the first initialization module 405 initializes the array-type members using the target name of the target union, that is, replaces the array-type members with vectors. <unknowtype>Therefore, regardless of the types of members included in the array type, it is universally applicable as a vector. <unknowtype>Because the `UnknowType` class's `Union` includes all supported types, during the creation and assignment of objects to members of an array, objects of the corresponding type can be created based on the type of the members in the array. This achieves the generalization of array representation and enables the use of `vector`. <unknowtype>The replacement of arrays enables nested arrays, thus supporting the creation of multidimensional arrays.

[0102] According to some embodiments, the data processing apparatus 400 further includes a second initialization module configured to initialize each member of the parent class before initializing each member of the data structure, in response to the data structure having a parent class.

[0103] Understandably, when a data structure has a parent class, the members of the parent class must be initialized before the members of the data structure are initialized, thus enabling the data processing device 400 to support class inheritance. The process of initializing the members of the parent class is similar to the process of initializing the members of the data structure, and will not be elaborated here.

[0104] According to some embodiments, the data processing apparatus 400 further includes a deinitialization module configured to deinitialize all initialized members and release the allocated memory in response to the completion of program execution based on the first data.

[0105] Understandably, after the program finishes running, the deinitialization module can restore the data by performing the reverse operation. At the same time, to avoid memory leaks, the allocated memory needs to be released.

[0106] According to another aspect of this disclosure, an electronic device is also provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform a data processing method.

[0107] According to another aspect of this disclosure, a non-transitory computer-readable storage medium storing computer instructions is also provided, wherein the computer instructions are used to cause the computer to perform a data processing method.

[0108] According to another aspect of this disclosure, a computer program product is also provided, including a computer program, wherein the computer program implements a data processing method when executed by a processor.

[0109] like Figure 5 As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. The RAM 503 may also store various programs and data required for the operation of the electronic device 500. The computing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0110] Multiple components in electronic device 500 are connected to I / O interface 505, including: input unit 506, output unit 507, storage unit 508, and communication unit 509. Input unit 506 can be any type of device capable of inputting information to electronic device 500. Input unit 506 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device, and may include, but is not limited to, a mouse, keyboard, touchscreen, trackpad, trackball, joystick, microphone, and / or remote control. Output unit 507 can be any type of device capable of presenting information, and may include, but is not limited to, a monitor, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 508 may include, but is not limited to, disk and optical disk. Communication unit 509 allows electronic device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth devices, 802.11 devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.

[0111] The computing unit 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above, such as data processing methods. For example, in some embodiments, the data processing method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the data processing method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform data processing methods by any other suitable means (e.g., by means of firmware).

[0112] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0113] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0114] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0115] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0116] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0117] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0118] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0119] While embodiments or examples of this disclosure have been described with reference to the accompanying drawings, it should be understood that the methods, systems, and devices described above are merely exemplary embodiments or examples, and the scope of the invention is not limited by these embodiments or examples, but only by the granted claims and their equivalents. Various elements in the embodiments or examples may be omitted or replaced by their equivalents. Furthermore, the steps may be performed in a different order than that described in this disclosure. Further, various elements in the embodiments or examples may be combined in various ways. Importantly, as the technology evolves, many elements described herein can be replaced by equivalents that appear after this disclosure.< / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype> < / unknowtype>

Claims

1. A data processing method, comprising: Define a target union with a target name, wherein the target union includes multiple members corresponding to multiple types, and wherein the multiple members include members of an array type, and the target name is an element of the member of the array type; Obtain first data having a data structure, wherein the data structure has at least one member; The first data is parsed to obtain the description information corresponding to the data structure; Based on the description information, determine the type of each member among the at least one member; Based on the type of each member in the data structure, determine the size of the memory to be requested and request memory of the corresponding size; and Based on the type of each member in the data structure, initialize each member in the allocated memory, including: In response to determining that the data structure includes members of type array, the members of type array are initialized in the allocated memory based on the target name of the target union.

2. The method according to claim 1, wherein, Determining the size of the memory to be requested based on the type of each member in the data structure includes: Based on the type of each member in the data structure, determine the memory size required to store each member; Based on the type of each member in the data structure, determine the memory size required for memory alignment when storing each member; and The size of the memory to be requested is determined based on the memory size required to store each member and the memory size required for memory alignment.

3. The method according to claim 2, further comprising: Determine whether the data structure has a parent class; In response to the data structure having a parent class, the memory size required for the parent class corresponding to the data structure is determined. The determination of the size of the memory to be requested based on the memory size required to store each member and the memory size required for memory alignment includes: The size of the memory to be requested is determined based on the memory size required to store each member, the memory size required for memory alignment, and the memory size required for the parent class corresponding to the data structure.

4. The method according to any one of claims 1-3, wherein, The initialization of each member of the data structure in the allocated memory based on the type of each member in the data structure further includes: In response to determining that the data structure includes members of a first type, the members of the first type are initialized to system default values ​​in the allocated memory, wherein the first type is one of an integer type and a floating-point type; and In response to determining that the data structure includes members of the second type, the members of the second type are initialized in the allocated memory using pointers, wherein the second type is one of string, structure, and union.

5. The method according to claim 3, further comprising: In response to the fact that the data structure has a parent class, the members in the parent class are initialized before the members in the data structure are initialized.

6. The method according to any one of claims 1-3, further comprising: In response to the completion of program execution based on the first data, all initialized members are deinitialized and the allocated memory is released.

7. A data processing apparatus, comprising: A definition module is configured to define a target union with a target name, wherein the target union includes multiple members corresponding to multiple types, and wherein the multiple members include members of an array type, and the target name is an element of the member of the array type; The acquisition module is configured to acquire first data having a data structure, wherein the data structure has at least one member; The parsing module is configured to parse the first data to obtain the description information corresponding to the data structure; The first determining module is configured to determine the type of each member among the at least one member based on the description information; The second determining module is configured to determine the size of the memory to be requested and request the corresponding size of memory based on the type of each member in the data structure; and A first initialization module is configured to initialize each member of the data structure in the allocated memory based on the type of each member in the data structure. The first initialization module includes: The third initialization unit is configured to initialize the array-type members in the allocated memory based on the target name of the target union in response to determining that the data structure includes array-type members.

8. The apparatus according to claim 7, wherein, The second determining module includes: The first determining unit is configured to determine the memory size required to store each member based on the type of each member in the data structure. The second determining unit is configured to determine, based on the type of each member in the data structure, the memory size required for memory alignment when storing each member; and The third determining unit is configured to determine the size of the memory to be requested based on the memory size required for each storage member and the memory size required for memory alignment.

9. The apparatus according to claim 8, further comprising: The third determining module is configured to determine whether the data structure has a parent class; The fourth determining module is configured to, in response to the data structure having a parent class, determine the memory size required by the parent class corresponding to the data structure. The third determining unit is further configured as follows: The size of the memory to be requested is determined based on the memory size required to store each member, the memory size required for memory alignment, and the memory size required for the parent class corresponding to the data structure.

10. The apparatus according to any one of claims 7-9, wherein, The first initialization module further includes: A first initialization unit is configured to, in response to determining that the data structure includes members of a first type, initialize the members of the first type to system default values ​​in the allocated memory, wherein the first type is one of an integer type and a floating-point type; and The second initialization unit is configured to initialize, in response to determining that the data structure includes members of a second type, members of the second type in the allocated memory using pointers, wherein the second type is one of a string, a structure, and a union.

11. The apparatus according to claim 9, further comprising: The second initialization module is configured to initialize each member of the parent class before initializing each member of the data structure, in response to the data structure having a parent class.

12. The apparatus according to any one of claims 7-9, further comprising: The deinitialization module is configured to deinitialize all initialized members and release the allocated memory in response to the completion of program execution based on the first data.

13. An electronic device, comprising: At least one processor; as well as A memory that is communicatively connected to the at least one processor; in The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.

14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.

15. A computer program product comprising a computer program, wherein, The computer program, when executed by a processor, implements the method of any one of claims 1-6.