+ 2

Why no change in emplace_back and push_back

Hi Trying to store string into vector. Tried two ways 1. Push_back and 2.emplace_back I could observe two allocations on heap for both approaches. Should emplace be more efficient than push here also ? Or am i missing something ? https://code.sololearn.com/cguwgpsC94LG/?ref=app

6th Apr 2023, 12:01 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Antwort
+ 4
Ketan Lalcheta maybe this might be helpful .. I would say emplace_back would be your best approach given this code however there may be times whereas yes push_back would qualify .. It really depends on what you intend to do. https://stackoverflow.com/questions/4303513/push-back-vs-emplace-back
10th Apr 2023, 5:03 AM
BroFar
BroFar - avatar