Hi,
Function return values versus "output" parameter, which one is faster? I think I best explain using what I am currently working on.
// specify identifier and return pointer.
SceneNode* createSceneNode(const String& desired_identifier); // f1
// auto-gen identifier and return as string.
String createSceneNode(SceneNode*& out_ptr_to_creation); // f2
// auto-gen identifier and return pointer to node
SceneNode* createSceneNode(String& out_gen_identifier); // f3
// auto-gen identifier and return as string.
void createSceneNode(SceneNode*& out_ptr_to_creation, String& out_gen_identifier); // f4
While I prefer f1 and f3, because they return SceneNode*, they result in ambiguos call. Furthermore, often, only SceneNode* is required. The String& in f3 will present some inconvenience and overhead, so I am planning on f1 and f2.
My question is, will there be a difference between
f2(node); // return value not assigned.
// will there be an optimisation NOT to copy string?
mystring = f2(node);
My guess is that function parameter storage should be in some very-fast-access area and will be readily available so output parameters work faster. however, if optimisation is done to prevent copy string in f2, then f2 will be better than f4.
I know in my example, this could be minimal, but I just want to know for knowledge/interest sake.
another side question: I always assume that references are 32bit data and passing reference is as fast as pointers, is that so?
Thanks. =)