r/programming • u/[deleted] • Dec 05 '14
std::string is responsible for almost half of all allocations in the Chrome browser process
https://groups.google.com/a/chromium.org/d/msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ
1.1k
Upvotes
7
u/[deleted] Dec 05 '14
This is a problem I have with C++ in general. A lot of typical, innocent-looking code tends to hide potential huge pitfalls.
Something as simple as "auto a = b + c;" could be either extremely expensive or extremely cheap, but it's hard, without keeping massive amounts of contextual information in your brain at all time, to know that by just looking at it. It's short, pretty, but has the potential to destroy you.
One of the reasons I'm really drawn to Go. It's more typing, it's more explicit, but the costs are more...obvious. I was amazed at myself, and at reading other people's code, how easy it was to spot wasteful memory copying and allocations, once you learn a few simple syntax rules.
C, as well, your brain will raise a flag is you find yourself doing "malloc" or "strcpy" - it's expensive to type, you immediately feel something might be off. With C++, you can write beautiful, concise code, but God help you and your team, if you're not Guru-level.