If you have functions with lots of parameters you should consider using a struct or class and pass the parameters by reference.

A reference or pointer is 4 bytes (on 32Bit systems). A function or method with a lot of parameters passed by value is more expansive than passing by reference because each parameter is copied on the stack.

If you have complex parameters like classes you should never pass them by value, because the constructors and destructors will be invoked.

Pass by value:

int doStuff(int a, int b) {
    return a + b;
}

doStuff(1, 2);

Pass by reference:

struct someData {
    int a, b;
};

int doStuff(const someData &foo) {
    return foo.a + foo.b;
}

someData foo;
foo.a = 1;
foo.b = 2;

doStuff(foo);

Add your comment now