News for hackers. Stuff that matters.
Re:Std::string half of all allocations in the Chrome browser... by ExpiredLink on Friday December 05, 2014 @09:10AM (#8704518)
During the 10 years I used C++ I never saw a project that used std::string as their standard string. The implementation of std::string not standardized. It may or may not have a 'small string optimization' which may not be an optimization at all. Instead of specifying a mundane immutable built-in string like in Java the C++ Standards committee decided to add even more 'advanced' features to an already overloaded language.
Re:Std::string half of all allocations in the Chrome browser... by richardwhiuk on Friday December 05, 2014 @09:22AM (#8704589)
Heh, as if Java's string was mundane, or even particularly well standardised. The implementation for String have varied in each of the JVM versions, and Android has a different version to the JDK.

Java's string, depending on the string, length, JVM version and a bunch of other factors may or may not:

- Be interned - so the result of "str1" == "str1" is compiler dependant (you must do "str1".equals("str1")).

- Maintain references to the string when doing a substring - e.g. "Java is a language full of quirks......".substring(0,4) may or may not hold a reference to the entire string. This has huge performance tradeoffs - e.g. if you parse JSON by doing .substring(), and aren't careful, then you can end up holding onto the entire unparsed JSON, even if you only keep track of a single obejct.

Re:Std::string half of all allocations in the Chrome browser... by kjetil on Friday December 05, 2014 @01:13PM (#8705890)
Are you seriously suggesting that String incompatibilites are a big issues in Java?

String interning is specified in the JLS: http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#...

As far as I can tell, the substring "feature" has been there since Java 1.0 and was fixed in Java 7. Hardly groundbreaking stuff.

Re:Std::string half of all allocations in the Chrome browser... by csl on Friday December 05, 2014 @09:28AM (#8704620)
The interface and behavior of std::string is standardized.

Library writers are free to implement it in any way that honors the standard. However, sometimes the requirements may lead to less than optimal implementations, I believe.

So as long as Chrome uses std::string for internal use only, there shouldn't be any problems. Using them across ABI boundaries, however, is another story.