I think references are usually treated exactly the same as pointers in the compiled machine code, but I'm not a compiler expert. The compiler just handles the stuff that the programmer would need to handle with pointers like getting addresses and dereferencing. Passing by reference should not be slower than anything else because there isn't any work done by the CPU in passing by reference that wouldn't have to be done to pass by value or pass a pointer. (Passing by reference is passing a memory address, but to pass by value you still need the address because it has to be dereferenced to get the value, which could be slow, so if anything I'd say passing by value could be slower) Of course, there can be exceptions if one thing or the other already happens to be in a register; I'm just speaking generally.
The point of passing a pointer by reference is to modify the value of the pointer in the function without having to deal with a second layer of pointers, not to save time or memory. Well, that's always the point of references, to do the same basic set of tasks as with pointers but without the possibility of pointer errors.
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln
Last edited by n0nsensical; 07-04-2005 at 07:26 PM..
|