confused with some_var.dup

Denis Koroskin 2korden at gmail.com
Fri Jan 16 12:53:24 PST 2009


On Fri, 16 Jan 2009 19:15:03 +0300, Qian Xu <quian.xu at stud.tu-ilmenau.de> wrote:

> Denis Koroskin wrote:
>>
>> The "Hello, World!" string is not allowed to be modified, because it  
>> could
>> be shared throughot the project and will be most probably put in a
>> read-only memory causing segfault at modification.
>>
>> But it you need to have a modified version of this this, you create its
>> copy (duplication, or 'dup' for short) and make whatever changes you  
>> want
>> to it...
>
> This confuses me very.
> Do you mean, there is no Copy-On-Write semantic in D?
> IMO, D-Compiler should make decision about whether to allocate a new  
> memory
> block, not programmer.
>
> --Qian

No, arrays have reference semantics (unlike std::string in C++) and thus changing data an array points to will have effect on all other arrays that share same data.



More information about the Digitalmars-d-learn mailing list