The pointer and the reference methods should be quite comparable (both in speed, memory usage and generated code).
Passing a class directly forces the compiler to duplicate memory and put a copy of the bar
object on the stack. What's worse, in C++ there are all sort of nasty bits (the default copy constructor and whatnot) associated with this.
In C I always use (possibly const) pointers. In C++ you should likely use references.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…