Friday, 16 August 2013

more efficient to create static local objects c++

more efficient to create static local objects c++

I'm wondering if the following
void foo()
{
static A var; //A is a class with a constructor
... //stuff done with var
}
is more efficient than
void foo()
{
A var; //A is a class with a constructor
... //stuff done with var
}
since the former would call A's constructor and destructor once rather
than the latter which does it per call of foo. I ask this question
generally across all local objects.

No comments:

Post a Comment