std::string 的两种实现方式

有两种:

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 项目

http://libcxx.llvm.org/

你可能感兴趣的:(String)