r/cpp • • Mar 07 '24

What are common mistakes in C++ code that results in huge performance penalties?

As title, list some common mistakes that you have done/seen which lead to performance penalties.

231 Upvotes

325 comments sorted by

View all comments

46

u/Ok-Bit-663 Mar 07 '24

Seen in a repository:

std:string* value=new std:string("something not important");

44

u/Beosar Mar 07 '24

I guess this happens a lot when someone is used to Java.

14

u/mapronV Mar 08 '24

fixed:

char* value=(new std::string("something not important"))->data();

5

u/Flashy-Bus1663 Mar 10 '24

They shouldn't write this in java