Object generation method and apparatus, storage medium, and electronic device
By including common attributes and a target algorithm in the target class, simultaneous memory allocation for the target object and the reference counter is achieved, solving the problem of low efficiency in the existing technology and improving the efficiency of object generation.
Patent Information
- Application Number
- CN202111301046.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-04
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2041-11-04
AI Technical Summary
In existing technologies, the separation of reference counters from type implementation results in two memory allocations being required when an object is created, leading to inefficiency.
The target class contains public attributes and a target algorithm for creating a reference counter, enabling the generation of the target object and the reference counter in a single memory allocation.
It improves the efficiency of object creation, achieving the generation of the target object and reference counter through a single memory allocation.
Smart Images

Figure CN114035778B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computer, in particular, to an object generation method and device, a storage medium and an electronic device. BACKGROUND
[0002] In the related art, the implementation of reference counting all contains a smart pointer in a package, the smart pointer points to a reference counting class, and the reference counting class points to a real object. That is, in the implementation, there is a reference counter and a pointer, and the pointer points to a type implementation. However, the implementation of reference counting in the related art separates the reference counter from the type implementation, resulting in two memory allocations when creating an object, which reduces efficiency. SUMMARY
[0003] This summary is provided to introduce a selection of concepts that are further described below in the detailed description. This summary is not intended to identify key or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
[0004] In a first aspect, the present disclosure provides an object generation method, comprising:
[0005] obtaining a target class, wherein the target class includes common attributes corresponding to the target class and a target algorithm for creating a reference counter;
[0006] generating a target object according to the common attributes in the target class and generating a reference counter of the target object according to the target algorithm in the target class.
[0007] In a second aspect, the present disclosure provides an object generation device, comprising:
[0008] an obtaining module configured to obtain a target class, wherein the target class includes common attributes corresponding to the target class and a target algorithm for creating a reference counter;
[0009] an object generation module configured to generate a target object according to the common attributes in the target class and generate a reference counter of the target object according to the target algorithm in the target class.
[0010] In a third aspect, the present disclosure provides a computer readable medium having a computer program stored thereon, the program being executed by a processing device to implement the steps of the object generation method of the first aspect.
[0011] In a fourth aspect, the present disclosure provides an electronic device, comprising:
[0012] a storage device having a computer program stored thereon;
[0013] a processing device configured to execute the computer program in the storage device to implement the steps of the object generation method of the first aspect.
[0014] By the above technical solution, the target class includes the shared attribute for creating the object and the target algorithm for creating the reference counter, and when the target object and the reference counter are created based on the target class, the memory spaces of the target object and the reference counter can be allocated at the same time, the target object is generated based on the shared attribute of the target class and the reference counter of the target object is generated according to the target algorithm by one-time memory allocation, and the generation efficiency of the instance object is provided.
[0015] Other features and advantages of the present disclosure will be described in detail in the following detailed description section. BRIEF DESCRIPTION OF DRAWINGS
[0016] The above and other features, advantages, and aspects of embodiments of the present disclosure will become more apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings in which:
[0017] Figure 1 is a flowchart of an object generation method according to an exemplary embodiment;
[0018] Figure 2 is a flowchart of obtaining a target class according to an exemplary embodiment;
[0019] Figure 3 is a relationship diagram of a new Object class and a target class according to an exemplary embodiment;
[0020] Figure 4 is a detailed flowchart of step 120 according to an exemplary embodiment;
[0021] Figure 5 is a relationship diagram of an Object class and an ObjectRef class according to an exemplary embodiment;
[0022] Figure 6 is a structural diagram of an object generation device according to an exemplary embodiment;
[0023] Figure 7 is a structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0024] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is understood that the present disclosure can be embodied in various forms and should not be interpreted in a limited sense as set forth in the embodiments set forth herein, but rather, the embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for illustrative purposes and are not intended to limit the scope of protection of the present disclosure.
[0025] It should be understood that each of the steps described in the method embodiments of the present disclosure can be performed in different orders and / or in parallel. In addition, the method embodiments can include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0026] The term "comprising" and variations thereof as used herein are open-ended, that is "including, but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Related definitions will be given in the description below.
[0027] It should be noted that the concepts of "first", "second", etc. mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not intended to limit the order or interdependence of the functions performed by these devices, modules or units.
[0028] It should be noted that the modification of "one" or "multiple" mentioned in the present disclosure is illustrative and not limiting, and those skilled in the art should understand that, unless otherwise explicitly indicated in the context, it should be understood as "one or more".
[0029] The names of the messages or information exchanged between the devices in the embodiments of the present disclosure are only for illustrative purposes, and are not intended to limit the scope of the messages or information.
[0030] Before the object generation method proposed in the present disclosure is described in detail, the concepts of related terms involved in the present disclosure are explained.
[0031] Class, the basis for information encapsulation in object-oriented programming (OOP, Object-Oriented Programming), is a collection of objects that have the same properties and methods. A class is a user-defined reference data type, also known as a class type. Each class contains data description and a set of functions that operate on data or pass messages.
[0032] Object, an instance of a class, is an instance obtained by instantiating a data structure defined by a class.
[0033] Object class, as a root class, all other classes are directly or indirectly inherited from the Object class.
[0034] ObjectPtr class, which is a user-defined smart pointer to the Object class, can be regarded as an encapsulation class of a simulated pointer to the Object class. The key data members of the ObjectPtr class include a pointer to the Object object and several key operator overload interfaces for obtaining a pointer or reference to the Object.
[0035] ObjectRef class, which can be regarded as an encapsulation class of the Object. The ObjectRef class includes the ObjectPtr to point to the Object.
[0036] The object generation method proposed in the disclosure will be described in detail below in combination with the accompanying drawings.
[0037] Figure 1 is a flowchart of an object generation method according to an exemplary embodiment. As shown in Figure 1 The object generation method provided by the embodiment of the disclosure can be applied to an electronic device, and can include the following steps.
[0038] In step 110, a target class is obtained, wherein the target class includes common attributes corresponding to the target class and a target algorithm for creating a reference counter.
[0039] Here, the target class can be a pre-created type, and the target class includes corresponding common attributes and a target algorithm for creating a reference counter. The common attributes corresponding to the target class refer to the attributes and methods common to the objects of the target class instance. For example, when the target class is a List (linked list) class, the List class includes common attributes for creating a List object and a target algorithm for creating a reference counter for the List object.
[0040] It is worth noting that the data structure of the target class can be represented as follows:
[0041] class class name {
[0042] attributes (variables) ;
[0043] behaviors (methods) ;
[0044] reference counter;
[0045] }
[0046] It should be understood that the target class can be any class including the common attribute and the target algorithm for creating the reference counter, can be the Object class, can be a subclass created based on the Object class, can be the ObjectRef class, and the like.
[0047] In step 120, a target object is generated according to the common attribute in the target class, and a reference counter of the target object is generated according to the target algorithm in the target class.
[0048] Here, the target object refers to an object instantiated based on the common attribute in the target class. The target object is generated by instantiating the data structure defined by the target class. The target object includes two data members (class electric quantity and instance variable) and methods. Among them, the class variable is common to all instantiated target objects, and the class variable is defined in the class and outside the function body. In the declaration of the class, the attribute is represented by a variable, which is called an instance variable. The reference counter is a memory management technique in computer programming languages, which can save the number of references of the target object, and when the number of references becomes zero, the memory of the target object is released.
[0049] Among them, when the target class is called to create the target object, since the target class includes the common attribute for creating the target object and the target algorithm for creating the reference counter, the first memory space for creating the target object and the second memory space for creating the reference counter of the target object can be allocated in the memory based on the target class, and then the target object is created in the first memory space based on the common attribute of the target class, and the reference counter of the target object is created in the second memory space based on the target algorithm.
[0050] For example, when creating a ListNode (a linked list object), since the List class corresponding to the ListNode includes the common attribute for creating the linked list object and the target algorithm for creating the reference counter of the linked list object, when the List class is called to create the ListNode, the memory of the reference counter of the ListNode and the memory of the vector (variable) for storing the ListNode can be allocated at the same time.
[0051] Therefore, by including the common attribute for creating the object and the target algorithm for creating the reference counter in the target class, when the target object and the reference counter are created based on the target class, the memory space of the target object and the reference counter can be allocated at the same time, the target object is generated based on the common attribute of the target class and the reference counter of the target object is generated according to the target algorithm by one memory allocation, so as to provide the generation efficiency of the instance object.
[0052] Figure 2is a flowchart of obtaining a target class according to an exemplary embodiment. As shown in Figure 2 the target class can be obtained by the following steps.
[0053] In step 101, an Object class is acquired, wherein the Object class includes common attributes corresponding to the Object class.
[0054] Here, the Object class is the root class of all Java classes, and all other classes directly or indirectly inherit from the Object class. The public String toString() method is defined in the Object class, which returns the string representation of the object, and the return value is a String type describing the relevant information of the current object. That is, the Object class includes common attributes (attributes and methods) corresponding to the Object class.
[0055] In step 102, the target algorithm is configured in the Object class to obtain a new Object class.
[0056] Here, the target algorithm for creating a reference counter is configured in the Object class to obtain a new Object class. In the new Object class, the common attributes corresponding to the Object class and the target algorithm are included. The data structure of the new Object class can be represented as follows: class Object{
[0057] attributes (variables);
[0058] behaviors (methods);
[0059] reference counter;
[0060] }
[0061] It should be understood that the new Object class is different from the traditional Object class, and the new Object class not only includes the common attributes of the traditional Object class, but also includes the reference count of the object.
[0062] In step 103, the target class is obtained based on the new Object class.
[0063] Here, after obtaining the new Object class, the target class can be obtained based on the Object class, so as to generate the target object and the reference counter corresponding to the target object based on the target class. In some implementable embodiments, the new Object class can be taken as the target class. In other implementable embodiments, a subclass can also be constructed based on the new Object class, and the subclass can be taken as the target class.
[0064] Figure 3 is a schematic diagram of the relationship between the new Object class and the target class according to an example embodiment. As shown in Figure 3 , the reference counter (RefCounter) is included in the new Object class, and when the target class is a subclass created based on the new Object class, the target class inherits from the new Object class, and the reference counter is also included in the target class. For example, when the ListNode is created, the List class is constructed based on the new Object class, and then the ListNode is created based on the List class. Since the List class inherits from the new Object class, the reference counter is included in the ListNode.
[0065] Therefore, by configuring the target algorithm for creating the reference counter in the Object class, the Object class with both common attributes and reference counting can be obtained. Any other class created based on the new Object class also inherits from the new Object class, and thus has the reference counter.
[0066] Figure 4 is a detailed flowchart of step 120 according to an example embodiment. As shown in Figure 4 , in some implementable embodiments, in step 120, generating the target object according to the common attributes in the target class and generating the reference counter of the target object according to the target algorithm in the target class can include the following steps.
[0067] In step 121, the target packaging class corresponding to the target class is obtained, wherein the target packaging class includes a first calling interface for packaging the common attributes in the target class and a second calling interface for packaging the target algorithm of the target class.
[0068] Here, the target packaging class refers to a class that packages the implementation method in the target class. In the target packaging class, the first calling interface for packaging the common attributes in the target class and the second calling interface for packaging the target algorithm of the target class. It should be understood that in the target class, the specific implementation method is exposed, and in the target packaging class, the interface is exposed, which packages the specific implementation method of the target class. For example,
[0069] In step 122, the target object is generated through the first calling interface of the target wrapper class, and the reference counter of the target object is generated through the second calling interface of the target wrapper class.
[0070] Here, when the target object is created based on the target wrapper class, the target object is generated through the first calling interface of the target wrapper class, and the reference counter of the target object is generated through the second calling interface of the target wrapper class.
[0071] Since the target wrapper class is a wrapper class referring to the target class, the interface is exposed to the user in the target wrapper class, and therefore, the creation of the target object based on the target wrapper class can solve the binary compatibility (ABI compatibility) problem, and the creation of the target object using the target wrapper class will not affect the previously compiled application.
[0072] In some embodiments, the target class is an Object class, and the target wrapper class is an ObjectRef class, wherein the ObjectRef class includes an ObjectPtr class, and the ObjectPtr class is used to point to the Object class through a smart pointer to encapsulate the Object class. Alternatively, the target class is a subclass created based on the Object class, and the target wrapper class is a sub wrapper class created based on the ObjectRef class, wherein the smart pointer of the ObjectPtr class in the sub wrapper class points to the subclass to encapsulate the subclass.
[0073] Here, when the target class is the Object class, the target wrapper class is the ObjectRef class. The ObjectRef class is a wrapper class pointing to the Object class, and the ObjectRef class includes an ObjectPtr class, and the ObjectPtr class is used to point to the Object class. For example, the ObjectRef class includes the statement "ObjectPtr <object>"ObjectPtr" is used to point to the Object class.
[0074] Since the Object class includes the common attributes of the Object class and the target algorithm for creating a reference counter, the encapsulation class ObjectRef class that references the Object class also has the common attributes of the Object class and the target algorithm for creating a reference counter. Moreover, since the ObjectRef class is an encapsulation class of the Object class, the specific implementation method is not exposed in the ObjectRef class, only the interface is exposed, and there is no ABI compatibility problem in creating an object based on the ObjectRef class.
[0075] Of course, in other embodiments, the target class can also be a subclass created based on the Object class, and the Object class includes the common attributes of the Object class and the target algorithm for creating a reference counter, and then the subclass created based on the Object class includes the common attributes of the subclass and the target algorithm. Then the target encapsulation class can be a sub-encapsulation class created based on the above-mentioned ObjectRef class, and since the ObjectRef class includes the ObjectPtr class pointing to the Object class, the ObjectPtr class in the created sub-encapsulation class will execute the subclass. For example, in the ListRef class (the encapsulation class of the List class), the "ObjectPtr <listnode>.
[0076] It is worth mentioning that in the object generation method proposed in the embodiments of the present disclosure, two base classes are actually proposed, namely the Object class and the ObjectRef class. The Object class includes common attributes of the Object class and a target algorithm for creating a reference counter. The ObjectRef class includes the ObjectPtr class, which points to the Object class through a smart pointer, so that the ObjectRef class also has the common attributes of the Object class and the target algorithm for creating a reference counter. In subsequent type system extensions, all other classes will inherit from the ObjectRef class and the Object class, thereby having specific common attributes and target algorithms for creating a reference counter.
[0077] The following will be described in detail in combination with the accompanying drawings. Figure 5 The above embodiments will be described in detail.
[0078] Figure 5 is a schematic diagram of the relationship between the Object class and the ObjectRef class according to an exemplary embodiment. As shown in Figure 5 RefCounter (reference counter) is included in the Object class. When a ListNode is created based on the Object class, the ListNode inherits the Object class and also has the RefCounter. The ObjectRef class is a wrapper class for referencing the Object class, and the ObjectRef class contains the ObjectPtr <object>ObjectPtr <object>The ObjectRef class points to an Object class, and therefore, the ObjectRef class also has a RefCounter.
[0079] The ListRef class is a child encapsulation class created based on the ObjectRef class, and in the ListRef class, the ObjectPtr <listnode>ObjectPtr <listnode>is a reference to the ListNode through the smart pointer. Since the ListRef class inherits from the ObjectRef class, an ObjectPtr will also be included in the ListRef class <object>member data_, which points to a ListNode when the List object is constructed. Since the ListNode inherits from the Object class, the ObjectPtr <object>It can also point to a ListNode, that is, the ListRef class has a RefCounter.
[0080] It should be understood that the object generation method provided by the present disclosure is only exemplified by the ListNode in the above embodiments, and does not limit the specific embodiments of the present disclosure.
[0081] Figure 6 is a structural schematic diagram of an object generation device according to an exemplary embodiment. As shown in Figure 6 The present disclosure proposes an object generation device 500, which can include:
[0082] The acquisition module 501 is configured to acquire a target class, wherein the target class includes a common attribute corresponding to the target class and a target algorithm for creating a reference counter;
[0083] The object generation module 502 is configured to generate a target object according to the common attribute in the target class and generate a reference counter of the target object according to the target algorithm in the target class.
[0084] In some embodiments, the device 500 further includes:
[0085] The type acquisition unit is configured to acquire an Object class, wherein the Object class includes a common attribute corresponding to the Object class;
[0086] The algorithm configuration unit is configured to configure the target algorithm in the Object class to obtain a new Object class;
[0087] The target class creation unit is configured to obtain the target class based on the new Object class.
[0088] In some embodiments, the target class creation unit includes:
[0089] The first creation subunit is configured to take the new Object class as the target class; or
[0090] The second creation subunit is configured to construct a subclass based on the new Object class and take the subclass as the target class.
[0091] In some embodiments, the object generation module 502 includes:
[0092] The encapsulation class obtaining unit is configured to obtain a target encapsulation class corresponding to the target class, wherein the target encapsulation class comprises a first calling interface for encapsulating the common attribute in the target class and a second calling interface for encapsulating the target algorithm of the target class.
[0093] The object creating unit is configured to generate the target object through the first calling interface of the target encapsulation class and generate a reference counter of the target object through the second calling interface of the target encapsulation class.
[0094] In some embodiments, the target class is an Object class, and the target encapsulation class is an ObjectRef class, wherein the ObjectRef class comprises an ObjectPtr class, the ObjectPtr class is used to point to the Object class through a smart pointer to encapsulate the Object class, or
[0095] The target class is a subclass created based on the Object class, and the target encapsulation class is a sub-encapsulation class created based on the ObjectRef class, wherein the smart pointer of the ObjectPtr class in the sub-encapsulation class points to the subclass to encapsulate the subclass.
[0096] In some embodiments, the object generating module 502 comprises:
[0097] The memory allocating unit is configured to allocate, based on the target class, a first memory space for creating the target object and a second memory space for creating a reference counter of the target object in the memory;
[0098] The object generating unit is configured to create, based on the common attribute of the target class, the target object in the first memory space; and
[0099] create, based on the target algorithm, the reference counter of the target object in the second memory space.
[0100] The specific implementation of each functional module of the apparatus in the above embodiments has been described in detail in the part about the method, and will not be repeated here.
[0101] Reference will be made to the following description of the embodiments of the present application with reference to the drawings. Figure 7 which shows a structural schematic diagram of an electronic device 600 suitable for implementing the embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure can include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Personal Computers), PMPs (Portable Multimedia Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and the like, as well as fixed terminals such as digital TVs, desktop computers, and the like. Figure 7 The electronic device shown is merely an example and should not bring any limitation to the function and scope of use of the embodiments of the present disclosure.
[0102] As shown, the electronic device 600 can include a processing device (e.g., a central processor, a graphics processor, etc.) 601 that can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 602 or loaded into a random access memory (RAM) 603 from a storage device 608. Various programs and data required for the operation of the electronic device 600 are also stored in the RAM 603. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604. Figure 7 Generally, the following devices can be connected to the I / O interface 605: input devices 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 608 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 609. The communication devices 609 can allow the electronic device 600 to communicate wirelessly or wired with other devices to exchange data. Although
[0103] The electronic device 600 is shown with various devices, but it is understood that all of the shown devices are not required to be implemented or provided. More or fewer devices can alternatively be implemented or provided. Figure 7
[0104] In particular, the processes described above with reference to the flowcharts can be implemented as a computer software program according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network through the communication devices 609, or installed from the storage devices 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the methods of the embodiments of the present disclosure are performed.
[0105] It should be noted that the computer-readable medium described above can be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any suitable combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program used by or in connection with an instruction execution system, apparatus or device. In the present disclosure, the computer-readable signal medium can include a data signal propagated in baseband or propagated as a carrier wave in a propagated data signal, in which the computer-readable program code is contained. Such a propagated data signal can take many forms, including but not limited to, an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium that can be used to carry or store program codes for use by or in connection with an instruction execution system, apparatus or device. Program codes contained in the computer-readable medium can be transmitted by any suitable medium, including but not limited to, a wire, an optical fiber, an RF (radio frequency) or the like, or any suitable combination of the above.
[0106] In some embodiments, the client, server, or both can communicate using any current known or future developed network protocol, such as HTTP (HyperText Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include local area networks ("LAN"), wide area networks ("WAN"), internetworks (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any current known or future developed networks.
[0107] The computer-readable medium described above can be included in the electronic device described above; or can exist separately from the electronic device and can not be assembled into the electronic device.
[0108] The computer readable medium described above carries one or more programs, which when executed by the electronic device, cause the electronic device to: acquire a target class, wherein the target class comprises a common attribute corresponding to the target class and a target algorithm for creating a reference counter; and generate a target object according to the common attribute in the target class and a reference counter of the target object according to the target algorithm in the target class.
[0109] Computer program code for carrying out operations of the present disclosure can be written in any one or more programming languages, including object oriented programming languages, such as Java, Smalltalk, C++, or conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0110] The flow diagrams and the block diagrams in the drawings are illustrations of architectures, functionalities, and operations of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flow diagrams or block diagrams can represent a module, a segment, or a portion of code, which comprises one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and / or flow diagrams, and combinations thereof, can be implemented by special purpose hardware-based systems that perform the specified functions or operations, or combinations of special purpose hardware and computer instructions.
[0111] The modules involved in the embodiments of the present disclosure can be implemented in the form of software or in the form of hardware. In some cases, the name of the module does not constitute a limitation on the module itself.
[0112] The functionality described above can be performed, at least in part, by one or more hardware logic components. For example, and without limitation, illustrative types of hardware logic components that can be used include Field-programmable Gate Arrays (FPGAs), Application-specific Integrated Circuits (ASICs), Application-specific Standard Products (ASSPs), System-on-a-chip systems (SOCs), Complex Programmable Logic Devices (CPLDs), etc.
[0113] In the context of the present disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more of: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0114] The above description is only that of preferred embodiments of the present disclosure and a description of principles of the technology employed. It should be understood by those skilled in the art that the scope of the disclosure involved is not limited to the technical solutions formed by the specific combinations of the above technical features, and should also cover other technical solutions formed by any combinations of the above technical features or equivalent features without departing from the above disclosed concept. For example, the technical solutions formed by the mutual replacement of the above features and the technical features disclosed in the present disclosure (but not limited to) having similar functions.
[0115] Further, while operations are depicted in a particular order, this should not be understood as requiring the operations to be performed in the particular order shown or in sequential order, and that certain operations can be performed in parallel or in any suitably ordered order under certain circumstances. Also, while a number of specific implementation details have been discussed, these should not be construed as limiting the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable sub-combination.
[0116] Although the subject matter has been described in language specific to structural features and / or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims. With respect to the devices in the above-described embodiments, in which various modules perform operations, the specific manner in which the various modules perform the operations has been described in detail in the embodiments relating to the method, and will not be described in detail here.< / object> < / object> < / listnode> < / listnode> < / object> < / object> < / listnode> < / object>
Claims
1. An object generation method characterized by comprising: The method comprises the following steps: acquiring a target class, wherein the target class comprises common attributes corresponding to the target class and a target algorithm for creating a reference counter; generating a target object according to the common attributes in the target class and generating a reference counter of the target object according to the target algorithm in the target class; the step of generating the target object according to the common attributes in the target class and generating the reference counter of the target object according to the target algorithm in the target class comprises the following steps: acquiring a target encapsulation class corresponding to the target class, wherein the target encapsulation class comprises a first calling interface for encapsulating the common attributes in the target class and a second calling interface for encapsulating the target algorithm of the target class; the target class is an Object class, and the target encapsulation class is an ObjectRef class, wherein the ObjectRef class comprises an ObjectPtr class, the ObjectPtr class is used for pointing to the Object class through a smart pointer to encapsulate the Object class; or the target class is a subclass created based on the Object class, and the target encapsulation class is a sub-encapsulation class created based on the ObjectRef class, wherein the smart pointer of the ObjectPtr class in the sub-encapsulation class points to the subclass to encapsulate the subclass; generating the target object through the first calling interface of the target encapsulation class and generating the reference counter of the target object through the second calling interface of the target encapsulation class.
2. The method of claim 1, wherein, The target class is obtained through the following steps: acquiring an Object class, wherein the Object class comprises common attributes corresponding to the Object class; configuring the target algorithm in the Object class to obtain a new Object class; obtaining the target class based on the new Object class.
3. The method of claim 2, wherein, The step of obtaining the target class based on the new Object class comprises the following steps: taking the new Object class as the target class; or constructing a subclass based on the new Object class and taking the subclass as the target class.
4. The method of claim 1, wherein, The step of generating the target object according to the common attributes in the target class and generating the reference counter of the target object according to the target algorithm in the target class comprises the following steps: allocating, based on the target class, a first memory space for creating the target object and a second memory space for creating the reference counter of the target object in a memory; creating, based on the common attributes of the target class, the target object in the first memory space; and creating, based on the target algorithm, the reference counter of the target object in the second memory space.
5. An object generation apparatus characterized by comprising: The method comprises the following steps: an acquiring module configured to acquire a target class, wherein the target class comprises common attributes corresponding to the target class and a target algorithm for creating a reference counter; The object generation module is configured to generate a target object according to the common attribute in the target class and generate a reference counter of the target object according to the target algorithm in the target class. The object generation module comprises: The encapsulation class acquisition unit is configured to acquire a target encapsulation class corresponding to the target class, wherein the target encapsulation class comprises a first calling interface for encapsulating the common attribute in the target class and a second calling interface for encapsulating the target algorithm of the target class; the target class is an Object class, and the target encapsulation class is an ObjectRef class, wherein the ObjectRef class comprises an ObjectPtr class, the ObjectPtr class is used to point to the Object class through an intelligent pointer to encapsulate the Object class; or the target class is a subclass created based on the Object class, and the target encapsulation class is a sub-encapsulation class created based on the ObjectRef class, wherein the intelligent pointer of the ObjectPtr class in the sub-encapsulation class points to the subclass to encapsulate the subclass; The object creation unit is configured to generate the target object through the first calling interface of the target encapsulation class and generate the reference counter of the target object through the second calling interface of the target encapsulation class.
6. The apparatus of claim 5, wherein, The apparatus further comprises: The type acquisition unit is configured to acquire an Object class, wherein the Object class comprises a common attribute corresponding to the Object class; The algorithm configuration unit is configured to configure the target algorithm in the Object class to obtain a new Object class; The target class creation unit is configured to obtain the target class based on the new Object class.
7. A computer readable medium having stored thereon a computer program, characterized in that The program is executed by the processing apparatus to implement the steps of the object generation method in any one of claims 1-4.
8. An electronic device, comprising: Comprise: A storage device having a computer program stored thereon; A processing device configured to execute the computer program in the storage device to implement the steps of the object generation method in any one of claims 1-4.