array initialization problem
Denis Koroskin
2korden at gmail.com
Mon Jan 19 02:00:00 PST 2009
On Mon, 19 Jan 2009 12:21:59 +0300, Qian Xu <quian.xu at stud.tu-ilmenau.de> wrote:
> Denis Koroskin wrote:
>
>> ...
>>
>> For example, let's modify CSTR and see what happens:
>> CSTR[0] = 'J'; // now it is "Jello"
>>
>> printing e.str and e2.str gives us the following output:
>> Jello
>> Jello
>>
>> ...
>
> Hi again,
>
> but there is one thing, I do not understand.
> CSTR is a constant. But with "CSTR[0] = 'J'", you can modify a const
> anyway,
> cannot you?
>
D1 has no const support.
> BTW: Do you know, why D do not use copy-on-write semantic instead of
> referencing? IMO, copy-on-write is much performanter.
>
> --Qian
It's not about performance (explicit memory management is faster, too), but semantics.
Arrays in D are reference types. Besides, it's best to avoid hidden allocations.
More information about the Digitalmars-d-learn
mailing list