CN110362334B - Method, device and medium for managing C + + object life cycle of secondary development language - Google Patents

Method, device and medium for managing C + + object life cycle of secondary development language Download PDF

Info

Publication number
CN110362334B
CN110362334B CN201910485835.3A CN201910485835A CN110362334B CN 110362334 B CN110362334 B CN 110362334B CN 201910485835 A CN201910485835 A CN 201910485835A CN 110362334 B CN110362334 B CN 110362334B
Authority
CN
China
Prior art keywords
secondary development
intelligent pointer
template
class
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910485835.3A
Other languages
Chinese (zh)
Other versions
CN110362334A (en
Inventor
陶超
韦锦超
吕时有
文述生
闫少霞
王江林
李宁
周光海
肖浩威
黄劲风
马原
徐丹龙
杨艺
丁永祥
刘国光
郝志刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Nanfang Intelligent Technology Co ltd
Original Assignee
Guangzhou Nanfang Intelligent Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Nanfang Intelligent Technology Co ltd filed Critical Guangzhou Nanfang Intelligent Technology Co ltd
Priority to CN201910485835.3A priority Critical patent/CN110362334B/en
Publication of CN110362334A publication Critical patent/CN110362334A/en
Application granted granted Critical
Publication of CN110362334B publication Critical patent/CN110362334B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention provides a C + + object life cycle management method of a secondary development language, which comprises the following steps: designing a reference counting mode, designing an intelligent pointer template class, designing an intelligent pointer template, compiling a generation mode code and configuring a secondary development environment. The invention relates to an electronic device and a readable storage medium, which are used for executing a C + + object life cycle management method of a secondary development language. The method solves the problem that the C + + common pointer object is easily released directly after being used by the secondary development language C #, JAVA and the like to cause system crash, ensures that the C + + memory data is correctly managed by the secondary development language, further improves the stability of the secondary development of the platform, enables secondary developers not to excessively consider the memory problem of the object, reduces the requirements of the technical capability of the developers, and enables the research and development platform to be easily developed by more people.

Description

Method, device and medium for managing C + + object life cycle of secondary development language
Technical Field
The invention relates to the technical field of cross-programming language development, in particular to a method, equipment and medium for managing a life cycle of a C + + object of a secondary development language.
Background
On the premise of development of a basic platform, in order to ensure that an autonomous development platform has higher operating efficiency, among many development languages, C + + is a very good choice, C + + is an object-oriented programming language, and many high-level programming languages perform encapsulation processing and optimization adjustment on the basis of C + +, so that C + + can naturally interact with these programming languages, while other languages have very high learning costs, such as assembly language, or are difficult to interact with other languages, such as C #, Java language, C language is a functional language, the programming difficulty is relatively high, and codes are difficult to manage and control, so C + + is selected as the programming language.
However, in the C + + programming implementation, the object pointer and the memory data are managed, a programmer needs to control the object pointer and the memory data by himself, most high-level programming languages such as C # and Java do not directly manage the objects of the programmer, and the management of the objects is processed through a garbage management mechanism of the high-level programming languages, so that the object memory does not need to be directly managed when the high-level languages such as C # and Java are written.
The SWIG tool is used as a code conversion tool, the internal use of an intelligent pointer comprises std in a C + +11 library, shared _ ptr, but C + +11 is not suitable for all platforms, and some older systems (window, linux, android and the like) cannot support C + +11, so that no way is provided for secondary development, the platform itself does not support the C + +11 standard library, and therefore std in the std, shared _ ptr and SWIG also support boost: : shared _ ptr, but since the C + + boost library is too large, the platform abandons the boost library in order to ensure the compactness and stability of the whole system. Therefore, a method for managing the life cycle of the object between the C + + and the object-oriented secondary development language is needed to solve the problem of system crash caused by the fact that the processing C + + ordinary pointer object is easily released by the secondary development language C #, JAVA, and the like directly after being used.
Disclosure of Invention
In order to overcome the defects of the prior art, the invention aims to provide a C + + object life cycle management method of a secondary development language, and solves the problem that a C + + common pointer object is easily released directly after being used by the secondary development language C #, JAVA and the like to cause system crash.
The invention provides a C + + object life cycle management method of a secondary development language, which comprises the following steps:
designing a reference counting mode, designing a class with the reference counting mode as a base class, writing member functions and member variables of reference counting into the base class, and inheriting the base class by all classes needing to use an internal intelligent pointer object;
designing an intelligent pointer template class, and directly managing reference counting inside the class, a common pointer of a C + + object and memory data by the class template through designing the class template;
designing an intelligent pointer template, obtaining the intelligent pointer template by an intelligent pointer template class which inherits the subclass of the base class and the subclass, designing the intelligent pointer template according to the statement and the definition mode of the macro in a code conversion tool, and modifying the implementation mode in the intelligent pointer template;
compiling generation mode codes, compiling an entry file of a code conversion tool, carrying out declaration marking on all class objects needing to be managed by using an intelligent pointer in the entry file by using the intelligent pointer template, executing commands by using a command tool mode of the code conversion tool, and generating formulated secondary development codes;
and configuring a secondary development environment, and generating all generated secondary development codes into corresponding dynamic link libraries and C + + libraries to be provided for secondary development users.
Further, in the step of designing an intelligent pointer template, the transcoding tool is specifically a simplified packet and an interface generator.
Further, in the step of designing the intelligent pointer template, the implementation manner in the intelligent pointer template is specifically a manner of modifying a secondary development language generated in the intelligent pointer template, a manner of generating a secondary development code when a C + + intelligent pointer is used as a parameter and a return value, a manner of entering a generated secondary development object into a C + + code, and a manner of managing an intelligent pointer when a class object of the secondary development language is transferred to a C + + terminal.
Further, in the step of designing the intelligent pointer template, when the reference count is converted into a secondary development object, a common object is changed into an intelligent pointer object to receive, and when the intelligent pointer object is converted into a common class of a secondary development language, the intelligent pointer template is used for marking.
Further, in the step of writing the generation mode code, the entry file is a file with i as a suffix.
Further, in the step of writing generation mode codes, the simplified package and the command tool mode of the interface generator are used for executing the commands of the simplified package and the interface generator, and the formulated secondary development codes, a plurality of secondary development language files, a file with a suffix of h and a file with a suffix of cxx are generated.
Further, the step of configuring the secondary development environment specifically includes the following steps:
compiling the file, compiling the generated file by using a compiling tool, compiling the file with the h as the suffix and the file with the cxx as the suffix through corresponding configuration, and compiling the file by using the compiling tool to generate a C + + dynamic link library;
packaging files, namely packaging all generated secondary development language files to generate a dynamic link library;
and (4) placing a file, and packaging and placing the C + + dynamic link library and all required dynamic link libraries in the project together under a root directory of a secondary development project operation program.
Further, in the step of compiling the file, the compiling tool comprises CMake and Visual Studio; in the step of packaging the files, a dynamic link library of C # is generated by using CMake configuration, or all the files are directly configured to an item of the dynamic link library of C # of Visual Studio to generate the dynamic link library.
An electronic device, comprising: a processor;
a memory; and a program, wherein the program is stored in the memory and configured to be executed by the processor, the program comprising a C + + object lifecycle management method for executing the above-described secondary development language.
A computer-readable storage medium having stored thereon a computer program for executing the above C + + object lifecycle management method of the secondary development language by a processor.
Compared with the prior art, the invention has the beneficial effects that:
the invention provides a C + + object life cycle management method of a secondary development language, which comprises the following steps: designing a reference counting mode, designing an intelligent pointer template class, designing an intelligent pointer template, compiling a generation mode code and configuring a secondary development environment. The invention relates to an electronic device and a readable storage medium, which are used for executing a C + + object life cycle management method of a secondary development language. The method solves the problem that the C + + common pointer object is easily released directly after being used by the secondary development language C #, JAVA and the like to cause system crash, ensures that the C + + memory data is correctly managed by the secondary development language, further improves the stability of the secondary development of the platform, enables secondary developers not to excessively consider the memory problem of the object, reduces the requirements of the technical capability of the developers, and enables the research and development platform to be easily developed by more people.
The foregoing description is only an overview of the technical solutions of the present invention, and in order to make the technical solutions of the present invention more clearly understood and to implement them in accordance with the contents of the description, the following detailed description is given with reference to the preferred embodiments of the present invention and the accompanying drawings. The detailed description of the present invention is given in detail by the following examples and the accompanying drawings.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
fig. 1 is a flowchart of a C + + object lifecycle management method for secondary development language according to the present invention.
Detailed Description
The present invention will be further described with reference to the accompanying drawings and the detailed description, and it should be noted that any combination of the embodiments or technical features described below can be used to form a new embodiment without conflict.
The C + + object lifecycle management method for the secondary development language, as shown in fig. 1, includes the following steps:
the method specifically comprises the following steps of customizing an intelligent pointer implementation mode belonging to a code conversion tool platform, and processing reference counting of a C + + class pointer object:
designing a reference counting mode, designing a class with the reference counting mode as a base class, writing member functions and member variables of reference counting into the base class, and inheriting the base class by all classes needing to use an internal intelligent pointer object; for example, the operation mode of reference counting is internally managed by a reference counting class refCount.
Designing an intelligent pointer template class, directly managing internal reference counting of the class by the class template through designing the class template, managing common pointers and memory data of the object, and ensuring that the whole C + + object has the characteristic of pointer memory consistency. Such as: template < class T >; class Smart _ Object {.. }, how the internal process calls the reference count change of refCount ().
Designing an intelligent pointer template, and obtaining the intelligent pointer template by an intelligent pointer template class which inherits the subclass of the base class and is used by the subclass, such as: b < C > is obtained by inheriting the subclass C of the class A with the reference counting mode and using an intelligent pointer template B < class >, wherein the class B represents an intelligent pointer template class, and the class represents the subclass inheriting the class with the reference counting mode, so that the object memory of the C realizes the function similar to the C + +11 intelligent pointer template std, shared _ ptr < class >. Besides, the reference counting template can be designed by imitating the mode of std, shared _ ptr for managing reference counting and the template of std, shared _ ptr.
The method specifically comprises the following steps of carrying out custom processing on the SWIG code conversion tool, ensuring that the C + + common object belongs to the intelligent pointer object after being converted:
designing an intelligent pointer template according to the statement and definition mode of macros in a code conversion tool, and modifying the implementation mode in the intelligent pointer template; preferably, the transcoding tool is specifically a simplified packet and interface generator (SWIG), and specifically, with reference to the declaration and definition manner of macros in the SWIG, similar to std: : shared _ ptr is defined in a way designed to handle intelligent pointer templates, e.g., declared as% Smart _ Object (TYPE … …). The C + + object is kept consistent by the programming method of code detail management based on the SWIG open source code conversion tool.
And modifying the mode of how to generate the secondary development language in the intelligent pointer template, wherein when the C + + intelligent pointer is encountered in the modified template as a parameter and used as a return value, how to generate the secondary development code, and meanwhile, how to modify the generated secondary development object to enter the C + + code, and how to manage the intelligent pointer when the class object of the secondary development language is transferred to the C + + end. In the whole process, reference counting is well processed and is generally designed as a C + + common pointer, when the C + + common pointer is converted into a secondary development object, the common object is changed into an intelligent pointer object to be accepted, and the reference counting is enabled to be increased by 1; the Smart pointer object is converted into a general class of a secondary development language by using a template mark, for example,% Smart _ object (C), where C is a subclass representing a class having a reference counting mode inherited.
The method for generating the secondary development code by using the SWIG specifically comprises the following steps:
compiling a generation mode code, compiling an entry file of a code conversion tool, and carrying out declaration marking on all class objects needing to be managed by using an intelligent pointer in the entry file by using an intelligent pointer template; the method comprises the following steps that an entry file of the SWIG is a file with i as a suffix, hereinafter referred to as an i file, specifically, the i file is written, and all class objects needing to be managed by using an intelligent pointer in the i file are declared and marked by using a% Smart _ Object () template, such as% Smart _ Object (C), wherein C is a subclass representing a class inheriting a reference counting mode;
and executing the SWIG command by using a SWIG command tool mode to generate a formulated secondary development code, and generating a plurality of secondary development language files (the generated files are related to the writing method of the i file), a file (C language header file) taking h as a suffix and a file (C language specific function implementation file) taking cxx as a suffix in the process.
And configuring a secondary development environment, and generating all generated secondary development codes into corresponding dynamic link libraries and C + + libraries of the platform for secondary development users. The method specifically comprises the following steps:
compiling the file, compiling the generated file by using a compiling tool, configuring a corresponding configuration pair, compiling the file with h as a suffix and the file with cxx as the suffix, and compiling the files by using the compiling tool to generate a C + + dynamic link library; adopting CMake, or configuring to Visual Studio, compiling to generate a C + + dll, wherein dll refers to dynamic link library;
packaging files, namely packaging all generated secondary development language files to generate a dynamic link library together; for example, C # files are configured and generated into C # dll by using CMake, or all files are directly configured into C # dynamic link library items of visual studio and directly generated;
and placing a file, packaging the C + + dll generated in the file compiling step, the dll in the original C + + project and the C # dll in the file packaging step together and placing the C + + dll and all the required dynamic link libraries in the project into a root directory of a secondary development project operation program, wherein the whole secondary development can be normally debugged and operated after the configuration.
An electronic device, comprising: a processor;
a memory; and a program, wherein the program is stored in the memory and configured to be executed by the processor, the program comprising a C + + object lifecycle management method for executing the above-described secondary development language.
A computer-readable storage medium having stored thereon a computer program for executing the above C + + object lifecycle management method for a secondary development language by a processor.
The invention provides a C + + object life cycle management method of a secondary development language, which comprises the following steps: designing a reference counting mode, designing an intelligent pointer template class, designing an intelligent pointer template, compiling a generation mode code and configuring a secondary development environment. The invention relates to an electronic device and a readable storage medium, which are used for executing a C + + object life cycle management method of a secondary development language. The method solves the problem that the C + + common pointer object is easily released directly after being used by the secondary development language C #, JAVA and the like to cause system crash, ensures that the C + + memory data is correctly managed by the secondary development language, further improves the stability of the secondary development of the platform, enables secondary developers not to excessively consider the memory problem of the object, reduces the requirements of the technical capability of the developers, and enables the research and development platform to be easily developed by more people.
The foregoing is merely a preferred embodiment of the invention and is not intended to limit the invention in any manner; those skilled in the art can readily practice the invention as shown and described in the drawings and detailed description herein; however, those skilled in the art should appreciate that they can readily use the disclosed conception and specific embodiments as a basis for designing or modifying other structures for carrying out the same purposes of the present invention without departing from the scope of the invention as defined by the appended claims; meanwhile, any changes, modifications, and evolutions of the equivalent changes of the above embodiments according to the actual techniques of the present invention are still within the protection scope of the technical solution of the present invention.

Claims (10)

1. The C + + object life cycle management method of the secondary development language is characterized by comprising the following steps of:
designing a reference counting mode, designing a class with the reference counting mode as a base class, writing member functions and member variables of reference counting into the base class, and inheriting the base class by all classes needing to use an internal intelligent pointer object;
designing an intelligent pointer template class, and directly managing reference counting inside the class, a common pointer of a C + + object and memory data by the class template through designing the class template;
designing an intelligent pointer template, obtaining the intelligent pointer template by an intelligent pointer template class which inherits the subclass of the base class and the subclass, designing the intelligent pointer template according to the statement and the definition mode of the macro in a code conversion tool, and modifying the implementation mode in the intelligent pointer template;
compiling generation mode codes, compiling an entry file of a code conversion tool, carrying out declaration marking on all class objects needing to be managed by using an intelligent pointer in the entry file by using the intelligent pointer template, executing commands by using a command tool mode of the code conversion tool, and generating formulated secondary development codes;
and configuring a secondary development environment, and generating all generated secondary development codes into corresponding dynamic link libraries and C + + libraries to be provided for secondary development users.
2. The C + + object lifecycle management method of a secondary development language of claim 1, wherein: in the step of designing the intelligent pointer template, the code conversion tool is specifically a simplified packet and an interface generator.
3. The C + + object lifecycle management method of a secondary development language according to claim 2, characterized in that: in the step of designing the intelligent pointer template, modifying the implementation mode in the intelligent pointer template specifically to modify the mode of generating a secondary development language in the intelligent pointer template; modifying the generation mode of the secondary development code when the C + + intelligent pointer is used as a parameter and a value is returned; modifying the mode of the generated secondary development object entering the C + + code; and modifying the mode of managing the intelligent pointer when the class object of the secondary development language is transferred to the C + + terminal.
4. The C + + object lifecycle management method of a secondary development language of claim 3, wherein: in the step of designing the intelligent pointer template, when the reference count is converted into a secondary development object, a common object is changed into an intelligent pointer object for receiving; and when the intelligent pointer object is converted into the common class of the secondary development language, the intelligent pointer template is used for marking.
5. The C + + object lifecycle management method of a secondary development language according to claim 2, characterized in that: in the step of writing the generation mode code, the entry file takes i as a suffix.
6. The C + + object lifecycle management method of a secondary development language of claim 5, wherein: in the step of writing the generation mode code, the simplified package and a command tool mode of the interface generator are used for executing commands of the simplified package and the interface generator, and the formulated secondary development code, a plurality of secondary development language files, one or more than one file with the suffix of h and one or more than one file with the suffix of cxx are generated.
7. The C + + object lifecycle management method of a secondary development language of claim 6, wherein: the step of configuring the secondary development environment specifically comprises the following steps:
compiling the file, compiling the generated file by using a compiling tool, compiling the file with the h as the suffix and the file with the cxx as the suffix through corresponding configuration, and compiling the file by using the compiling tool to generate a C + + dynamic link library;
packaging files, namely packaging all generated secondary development language files to generate a dynamic link library;
and (4) placing a file, and packaging and placing the C + + dynamic link library and all required dynamic link libraries in the project together under a root directory of a secondary development project operation program.
8. The C + + object lifecycle management method of a secondary development language of claim 7, wherein: in the file compiling step, the compiling tool comprises CMake and Visual Studio; in the step of packaging the files, a dynamic link library of C # is generated by using CMake configuration, or all the files are directly configured to an item of the dynamic link library of C # of Visual Studio to generate the dynamic link library.
9. An electronic device, characterized by comprising: a processor;
a memory; and a program, wherein the program is stored in the memory and configured to be executed by the processor, the program comprising instructions for carrying out the method of any one of claims 1-8.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that: the computer program is executed by a processor for performing the method according to any of claims 1-8.
CN201910485835.3A 2019-06-05 2019-06-05 Method, device and medium for managing C + + object life cycle of secondary development language Active CN110362334B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910485835.3A CN110362334B (en) 2019-06-05 2019-06-05 Method, device and medium for managing C + + object life cycle of secondary development language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910485835.3A CN110362334B (en) 2019-06-05 2019-06-05 Method, device and medium for managing C + + object life cycle of secondary development language

Publications (2)

Publication Number Publication Date
CN110362334A CN110362334A (en) 2019-10-22
CN110362334B true CN110362334B (en) 2021-02-02

Family

ID=68215614

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910485835.3A Active CN110362334B (en) 2019-06-05 2019-06-05 Method, device and medium for managing C + + object life cycle of secondary development language

Country Status (1)

Country Link
CN (1) CN110362334B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111061459A (en) * 2019-12-11 2020-04-24 智器云南京信息科技有限公司 Packaging method and system of graph computation library, storage medium and electronic equipment
CN111061468B (en) * 2019-12-20 2023-10-10 北京爱奇艺科技有限公司 Mapping method and device
CN113760396A (en) * 2020-07-01 2021-12-07 北京沃东天骏信息技术有限公司 Application running method and device, electronic equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1889038A (en) * 2006-08-03 2007-01-03 上海科泰世纪科技有限公司 Method for managing long-distance structural components service cycle with class as unit
CN109067562A (en) * 2018-06-27 2018-12-21 武汉斗鱼网络科技有限公司 Dynamic configuration update method and system, server and medium based on intelligent pointer

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8417744B2 (en) * 2011-03-23 2013-04-09 Microsoft Corporation Techniques to manage a collection of objects in heterogeneous environments
US10162614B2 (en) * 2016-04-23 2018-12-25 International Business Machines Corporation Warning data management with respect to a compilation phase

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1889038A (en) * 2006-08-03 2007-01-03 上海科泰世纪科技有限公司 Method for managing long-distance structural components service cycle with class as unit
CN109067562A (en) * 2018-06-27 2018-12-21 武汉斗鱼网络科技有限公司 Dynamic configuration update method and system, server and medium based on intelligent pointer

Also Published As

Publication number Publication date
CN110362334A (en) 2019-10-22

Similar Documents

Publication Publication Date Title
CN110362334B (en) Method, device and medium for managing C + + object life cycle of secondary development language
Aßmann et al. Invasive software composition
CN110149800B (en) Apparatus for processing abstract syntax tree associated with source code of source program
US6877155B1 (en) System and method for generating target language code utilizing an object oriented code generator
WO2019237701A1 (en) Cross-language programming
KR101795844B1 (en) Runtime system
US8707278B2 (en) Embedding class hierarchy into object models for multiple class inheritance
WO2006017944A1 (en) Method and system for bi-directional data conversion between iec 61970 and iec 61850
US20060130015A1 (en) Defining expressions in a meta-object model of an application
CN104932905A (en) Automatic code generation method from AADL to C language
US6446259B2 (en) System and method for generating an object structure at run time in an object-oriented programming language
CN109976723B (en) Algorithm development platform, algorithm development method and computer readable storage medium
CN109799971B (en) File generation device and method
US7120618B2 (en) System and method for defining and using subclasses declaratively within markup
CN110457013B (en) Program component configuration device and method
CN111552480B (en) Cross-platform compiling method, device, equipment and readable storage medium
Edmunds et al. Tool support for Event-B code generation
CN110780863A (en) Cross-platform development method, device, equipment and medium of storage system
CN112148283B (en) Method for realizing cross-platform ABI compatible C++ component framework
CN110673890B (en) Plug-in calling method, system, medium and device
KR100576941B1 (en) Metamodel-based model transformation apparatus
CN108984163A (en) A kind of multi-platform code generating method of isomery formula based on IMCL model
CN115586904B (en) JSON data format description-based dynamic generation method for Java beans
WO2008015110A2 (en) Methods, apparatus and computer programs for modelling computer programs
US7580962B1 (en) Automatic code generation for co-simulation interfaces

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant