< Previous | Contents | Next >
Passing References for Efficiency
Passing a variable by value creates some overhead because you must copy the variable before you assign it to a parameter. When we’re talking about variables of simple, built-in types, such as an int or a float, the overhead is negligible. But a large object, such as one that represents an entire 3D world, could be expensive to copy. Passing by reference, on the other hand, is efficient because you don’t make a copy of an argument variable. Instead, you simply provide access to the existing object through a reference.