3 ms·
> copy-on-write-unless-we're-alone-then-just-mutate-without-copy well, yes, that's generally called copy-on-write. A COW class which does a copy every time you
by jcelerier 9y ago
> copy-on-write-unless-we're-alone-then-just-mutate-without-copy
well, yes, that's generally called copy-on-write. A COW class which does a copy every time you write to it would be pretty useless, woudln't it ?
e.g. if you did, in old std::strings:
std::string s = "foo";
s[1] = "x"; // no copy here
auto s2 = s; // no copy here;
s[1] = "y"; // s is copied in a new buffer
s[1] = "z"; // no copy here
s2 += "bar"; // no copy here