Assuming we are running a compiled C++ binary:
Is passing around an int
(e.g. function to function, or writing it into variables) slower than passing around structs/class objects like the following?
class myClass
{
int a;
int b;
char c;
vector d;
string e;
}
It depends on several factors, including the complexity of the copy-constructor and whether the compiler can do elision.
Any time something gets copied how long it takes is going to be a direct result of how big that thing is and what things its copy constructor does; obviously that class is larger than a single int, so it would be slower. If you pass a pointer or pass the thing by reference, there's no copy required and it takes the same amount of time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With