Re: Returning classes with pointers to buffers
On Fri, 7 Mar 2008 18:50:11 +0100, "Giovanni Dicanio"
<giovanni.dicanio@invalid.com> wrote:
Doug: considering your high-level C++ knowledge, do you also think that COW
is worst in performance than non-COW implementations (like std::string) ?
Like most things, it depends. The main reason std::string implementations
moved away from copy-just-in-case was for thread safety. The C++ Standard
requires string::reference to be a real reference type, and this means it
doesn't allow true copy-on-write, just this poor approximation I've always
called "copy-just-in-case". That's the reason for most of the really odd
rules concerning invalidation, and it is what made it hard if not
impossible to make unsharing thread-safe. In time, copy-just-in-case was
recognized as an idea that didn't work, and it was abandoned. Since the
standard doesn't allow copy-on-write, this meant moving to a non-reference
counted approach, and for those loath to give up all the perceived
performance benefits of reference counting, the "small string optimization"
was born.
--
Doug Harrison
Visual C++ MVP