Adding objects to vectors vs adding pointers to vectors in c++.
Example:
std::vector<Size> buildings;
Size building(buildingWidth, buildingHeight);
buildings.push_back(building);
VS
std::vector<Size*> buildings;
Size *building = new Size(buildingWidth, buildingHeight);
buildings.push_back(building);
Which one is better in terms of memory/performance?
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.
The second one creates an object on the heap. There is one instantiation, but there is no copy into the vector.
Am I correct?