我刚刚阅读了一篇关于 Copy-on-write 的 Wikipedia 文章(好奇是否有任何文件系统支持它),并对以下段落感到惊讶:
COW 也用于内核之外的库、应用程序和系统代码中。例如,C++ 标准库提供的字符串类是专门为允许写时复制实现而设计的:
std::string x("Hello");
std::string y = x; // x and y use the same buffer
y += ", World!"; // now y uses a different buffer
// x still uses the same old buffer
我不知道 STL 都支持写时复制。真的吗?它是否适用于其他 STL 类,例如std::vector
或std::array
?哪些编译器支持这种优化(特别是,我想知道 G++、英特尔 C++ 编译器和 Microsoft C++ 编译器)?