Adding objects to vectors vs adding pointers to vectors in c++?
<p>Adding objects to vectors vs adding pointers to vectors in c++.</p>

<p>Example:</p>

<pre><code>std::vector&lt;Size&gt; buildings;
Size building(buildingWidth, buildingHeight);
buildings.push_back(building);
</code></pre>

<p>VS</p>

<pre><code>std::vector&lt;Size*&gt; buildings;
Size *building = new Size(buildingWidth, buildingHeight);
buildings.push_back(building);
</code></pre>

<p>Which one is better in terms of memory/performance?</p>

<p>The first one basically creates an object on the stack and adds it to a vector.
So there is one instantiation followed by one copy into the vector.</p>

<p>The second one creates an object on the heap.
There is one instantiation, but there is no copy into the vector.</p>

<p>Am I correct?</p>
