Using references to objects

Many functions return a reference to an object rather than an object. Returning a reference is much more efficient because it avoids unnecessary memory operations. To maintain the efficiency of references, you should use the reference itself. You should not assign the reference to a new object, since assigning the reference to a new object creates a copy of the object that is denoted by the reference and invokes potentially expensive copy constructors. For example,


    odb_Instance instance = odb.rootAssembly().instances()
                            ["PART-1-1"];
    const odb_SequenceNode nodeSequence = myInstance.nodes();
 
In the above case a copy of the nodeSequence object has to be created in memory.

Many of the methods in the Abaqus Scripting Interface that provide access to an output database return a reference to an object rather than the object itself. It is much more efficient to modify the previous example to specify the returned type to be a reference:


    odb_Instance& instance = odb.rootAssembly().instances()
                             ["PART-1-1"];
    const odb_SequenceNode& nodeSequence = myInstance.nodes();
 

In this case no new object is created and no copy constructors are called.