有两种:
1. COW(copy on wirte):
是当前主流的实现,不过在多线程环境下会有性能问题
参考:
How is std::string implemented?
http://stackoverflow.com/questions/1466073/how-is-stdstring-implemented
Copy-On-Write的原理及具体实现
Copy On Write(写时复制)
2.Short string optimization
为解决cow暴露的问题而出现另一种实现方案,llvm子项目“新libc++ 0x"采用这种实现。
From years of experience (including having implemented the standard library before), we've learned many things about implementing the standard containers which require ABI breakage and fundamental changes to how they are implemented. For example, it is generally accepted that building std::string using the "short string optimization" instead of using Copy On Write (COW) is a superior approach for multicore machines (particularly in C++'0x, which has rvalue references). Breaking ABI compatibility with old versions of the library was determined to be critical to achieving the performance goals of libc++.
参考
libc++ 0x 项目
本文详细解析了C++字符串实现中的两种主要技术:Copy-On-Write(写时复制)与短字符串优化,并阐述了在多核机器上使用短字符串优化作为替代方案的性能优势,同时介绍了新libc++0x项目对此的采用。
1500

被折叠的 条评论
为什么被折叠?



