Re: A question about efficiency
- From: "Frederic Fuzier" <remove_ffuzier@xxxxxxxxxxxx>
- Date: Wed, 25 Jan 2006 12:26:32 +0100
Regarding efficiency, if you pass a parameter by reference because you only
want to avoid the copy, it's better to have a parameter which is a const
reference.
void func2(const float &f, float &g)
{
g = f + 10;
}
Doing this, the call can be made both on a const and non-const f object,
even a literal value.
As a side effect, it allows implicit conversion, for instance from int
In func2, g is then documented as an in/out parameter.
As Uli has suggested for his function add_10, func1 could be write as :
float func1(float f)
{
return (f+10.0f);
}
for an object more complex than a float the compiler may optimize the code
with the "return value optimization" which avoids the creation of temporary
objects.
Fred
.
- Follow-Ups:
- Re: A question about efficiency
- From: Ben Voigt
- Re: A question about efficiency
- From: Alexander Grigoriev
- Re: A question about efficiency
- References:
- A question about efficiency
- From: David++
- Re: A question about efficiency
- From: Ulrich Eckhardt
- A question about efficiency
- Prev by Date: Re: release build assertions/verifications
- Next by Date: XML connectivity
- Previous by thread: Re: A question about efficiency
- Next by thread: Re: A question about efficiency
- Index(es):
Relevant Pages
|