对每一位C++爱好者或C++专业程序员来说,Herb Sutter的名字应该不会让人感到陌生。作为ISO/ANSI C++标准委员会的委员,Herb Sutter不仅是C++程序设计领域公认的专家,还是深受程序员喜爱的技术讲师和作家。Herb Sutter在互联网上主持的Guru of the Week专栏广受欢迎,几乎成为每一位C++程序员的网上必读物。本书就是Guru of the Week的最新精华总结。
本书的独特之处在于其对“复杂性”的坦诚态度。作者并未试图简化C++的难懂之处,而是直面诸如Copy-on-Write在多线程下的性能陷阱、内联函数对Profiling工具的干扰等现实矛盾。这种不回避争议、甚至主动制造认知冲突的写作方式,使得本书在同类技术书籍中独树一帜。然而,其局限也显而易见:内容高度依赖特定的编译器行为和旧版标准,缺乏对现代并发模型和移动语义的系统性更新。因此,它更适合作为辅助读物,与《Effective Modern C++》等新书搭配使用,前者负责夯实底层原理与防御性编程意识,后者负责拥抱新特性,二者互补方能构建完整的C++知识体系。
"Make a function inline directs the compiler that it may choose to place a copy of the function's code directly into each place the code is used. In the cases where the compiler does so, it avoids generating a function call."
"If you're looking to improve efficiency in some way, always look to your algorithms and data structures first."
"Finally, note another practical reason for this: Profilers are a lot less good at identifying which inlined functions should NOT be inlined."
"Avoid inlining or detailed tuning until performance profiles prove the need."
"Without atomic integer operations, copy-on-write typically incurs a significant performance penalty. Even with atomic operations, COW can make common String operations take nearly 50% longer, even in single-threaded programs."
"In general, copy-on-write is often a bad idea in multithread-ready code. That's because the calling code can no longer know whether two distinct String objects actually share the same representation under the covers, so String must incur overhead to do enough serialization so that calling code can t"
"Most of COW(copy-on-write)'s primary advantage for small strings could be gained without COW by using a more efficient allocator."