Hi,
I'm having problems with dynamic memory, and returning values from functions. Consider the following function signature:
And the calling:
The calling can be optimized through return value optimization (RVO), such that no copying needs to take place. The caller will get the value on its stack directly, and no heap memory will be used.
Now, my question is: can the same thing be accomplished without relying on RVO (i.e accomplish the same thing explicitly)? If not, is there any specific reasons why this is? I think I am confused about when dynamic memory should be used and not. I find myself wanting to acheive this very often.
Thanks
I'm having problems with dynamic memory, and returning values from functions. Consider the following function signature:
Code:
Thing buildThing() { return ThingImpl; }
Code:
Thing& t = buildThing();
Now, my question is: can the same thing be accomplished without relying on RVO (i.e accomplish the same thing explicitly)? If not, is there any specific reasons why this is? I think I am confused about when dynamic memory should be used and not. I find myself wanting to acheive this very often.
Thanks
Comment