Why I (Still) Won't Use D

Janice Caron caron800 at googlemail.com
Fri Mar 28 01:15:26 PDT 2008


On 28/03/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
> Yet I'm always left wondering what is the difference between vector and
> string?

In Microsoft Visual Studio's implementation, std::string implements
copy-on-write, wheras std::vector doesn't. e.g.

    std::vector<char> v1 = whatever;
    std::vector<char> v2 = v1; // makes a copy

    std::string s1 = whatever;
    std::string s2 = s1; // no copy made, YET

    s2[0] = 'x'; // NOW a copy is made

This is purely an implementation difference. It is not specified in
the standard.

D takes a sort of halfway-in-between approach. In D, we copy arrays
(including strings) by reference, and implement copy-on-write in the
algorithms; In MSVC++ one copies vectors and string by value, and
copy-on-write is implemented in the design of std::string.



More information about the Digitalmars-d mailing list