Re: why Visual Studio can not optimize the initialization code?
Thanks Igor,
My question is almost answered. Finally, I want to confirm,
In the simple sample from MSDN,
it only saves the time of,
1. constructor of temporary object;
2. destructor of temporary object;
And it can not save time of the assignment operator. :-)
--------------------
#include <stdio.h>
class RVO
{
public:
RVO(){printf("I am in constructor\n");}
RVO (const RVO& c_RVO) {printf ("I am in copy constructor\n");}
~RVO(){printf ("I am in destructor\n");}
int mem_var;
};
RVO MyMethod (int i)
{
RVO rvo;
rvo.mem_var = i;
return (rvo);
}
int main()
{
RVO rvo;
rvo=MyMethod(5);
}
--------------------
regards,
George
"Igor Tandetnik" wrote:
"George" <George@discussions.microsoft.com> wrote in message
news:85377BC1-552F-4608-AB2A-B111324571DB@microsoft.com
I think NRVO could only optimize in the case of return value from a
function. From the name -- Named Return Value Optimization (NRVO), it
seems that only return value from a function could be optimized.
Yes, RVO (whether Named or otherwise) only applies to function return
values.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925