Rule Definition
In C++, passing a 'class' or 'struct' object by value creates a copy of the object, by calling the copy constructor of the class. This copy can be slow, especially on big objects. The same applies for C 'struct' even if the copy constructor is not called.
Remediation
Pass the argument by reference (with 'const'). This may require that you add missing 'const' qualifiers to class functions.
Violation Code Sample
class Matrix
{
public:
Matrix(Matrix const &m); // Copy constructor
private:
double *data; // Can be really big
// ...
};
void display(Matrix m); // VIOLATION
Fixed Code Sample
class Fraction
{
private:
int numerator;
int denominator;
// ...
};
void display(Matrix const &m);
Related Technologies
C++
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.