< 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 were 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 dont make a copy of an argument variable. Instead, you simply provide access to the existing object through a reference.


 

Introducing the Inventory Displayer ProgramUnderstanding the Pitfalls of Reference PassingDeclaring Parameters as Constant ReferencesPassing a Constant Reference