4 ms·
The second link is not a good example of C++ imposing a cost for something you don't use. It's just a bad performance trade-off in std::string. The standard l
by dkarl 14y ago
The second link is not a good example of C++ imposing a cost for something you don't use. It's just a bad performance trade-off in std::string. The standard library types aspire to be useful in a wide range of performance-sensitive applications, but if they don't work for you, you are free to use alternatives. Programmers at my company use a variety of C++ containers that are faster than the STL containers for particular uses.
The first link is a reasonable example of paying a cost for something you might not use. However, I disagree with the article when it says there's no good reason for it. People really do compare function pointers for equality. A common example is when different functions implement different "strategies" (to use the GOF term.) A simulation might customize the behavior of simulation objects using pointers to different strategy functions, and you might compare the pointers to find all the simulation objects that follow a particular strategy, or to check whether two objects use the same strategy. Since implementations are free to inline functions that are not declared "inline," there would be no valid way to compare function pointers if an inlined function could have different addresses in different translation units.
Adding performance at the expense of sanity should be voluntary, not the default behavior. (It definitely counts as insanity if comparing &my_handy_function and &my_handy_function for equality returns false in a language where function pointers are the only way to treat a function as data.) Anyone who is picky enough about performance to be concerned about link time is on intimate terms with their implementation(s) anyway, so I think it's perfectly acceptable for such an optimization to be available through non-standard flags. Although, if any language were to standardize insanity, perhaps it would be appropriate for it to be C++.