back
1 comments
I understand that Move Semantics led to better implementations and that this is why things changed. I know that in this case, problems arose when transitioning from C++98 to what's commonly called Modern C++ (C++11). However, I'm not very familiar with what the specific issues were with COW. If you happen to know of any documents that describe this problem in more detail, I'd appreciate it if you could let me know. I'm sorry for always asking questions. I've looked up a few documents, but since you clearly know much more about this than I do, I'm asking to study it myself as well. If it's too much trouble, feel free not to reply.
The changes to std::string were made because "the [pre-C++11] definition of basic_string allows only very limited concurrent access to strings. Such limited concurrency will inhibit performance in multi-threaded applications." The proposed fix was to make "all iterator and element access operations safely concurrently executable." [0]. This involved limiting the circumstances in which iterators could be invalidated, which among other things meant that non-const operator[] could no longer invalidate iterators, which meant copy-on-write was no longer a viable implementation [1].

[0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n26...

[1]: https://stackoverflow.com/q/12199710

Thank you for the kind comment. !
Asking questions is always a good thing so don't worry about it. It makes us think and check our own understanding too, so we also learn something :-)

A nice succinct post by Pavel Khaipov; Copy-on-Write in Modern C++: Why the Standard Dropped It - and Why Qt Still Uses It - https://www.linkedin.com/posts/khaipov_copy-on-write-in-mode...

A detailed post by Andrii Nikishaiev; Why Copy-On-Write (COW) removed in C++? - https://www.linkedin.com/pulse/why-copy-on-write-cow-removed...

The std document on Concurrency Modifications to Basic String - https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n25...

Finally, C++11 tightened the specification for std::string viz. contiguous memory, some methods must have O(1) access time, when references/iterators/pointers can/cannot be invalidated etc. which doomed COW.

I'm sorry for always bothering you, senior. I've learned quite a lot from the books you recommended. I've especially been studying low-level topics lately, and the books you suggested have been very helpful. Have a great day.
I am glad that you found my comments useful. I use HN as my "blog" and generally include references to books/papers/articles as a pointer to further information on a topic. You will find links to lots of books if you search my comments for key phrases (eg. embedded, book etc.).

One thing i try to do is point people to lesser-known but very good and advanced books. I generally find that most HN book suggestions refer only to popular books most of which are just so-so while many great books remain unknown which is a shame. For example how many people know of Operating Systems in Depth by Thomas Doeppner? It has lots of helpful illustrations, compares concepts in both Linux/Windows implementations and is an all-round great book. I really understood the nuances of signal handling between kernel/user modes when i read it here.