title: Creating and returning a big object from a function
body: <p>Imagine such situation that I have a function like this:</p>
  
  <pre><code>Object f()
  {
      Object obj;
      return obj;
  }
  </code></pre>
  
  <p>Where <code>sizeof(Object)</code> is a big value.</p>
  
  <p>And then I make a call of this function:</p>
  
  <pre><code>Object object = f();  
  </code></pre>
  
  <p>Do i understand correctly that first Object will be created on a stack (in the function) and then will be copied to object variable?</p>
  
  <p>If so, is it reasonably to create an object in the function on a heap and to return a pointer to it instead of a copy ?</p>
  
  <p>But i mean that the object must be created in the <code>f()</code> function - not passed by a pointer or a reference to this function and initialized.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I don't mean that f is a very simple function. It can have a really complex routine of object initialization depending on some context. Will the compiler still optimize it as well?</p>