ref?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Feb 15 09:39:11 PST 2009
Jerry Quinn wrote:
> dsimcha Wrote:
>
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
>> article
>>> Walter and I have been discussing what the regime of
>>> statically-sized arrays should be. In short, the behavior that's
>>> most consistent with everything else is to treat them as values.
>>> This also brings the problems of e.g. containers - should they
>>> have consistent value semantics (like in STL)
>> Oh God no! I always thought the value semantics of STL containers
>> were largely a kludge to work around the fact that C++ doesn't have
>> garbage collection. They make it easier to use RAII for memory
>> management, since every object has a clear owner. This leads to
>> tons and tons of copying if code is written the obvious way, and
>> lots of kludges to prevent it.
>
> On the other hand, for relatively small objects, the last thing I
> want is to have everything be a reference. This is one of the major
> flaws of Java, I think, from a memory efficiency standpoint. I'd
> hate to have to have references to 16 byte objects if I don't need
> the sharing behavior.
>
> Having classes with reference semantics in D largely solves this
> issue, doesn't it? Use a class when you have things that make sense
> to share, and use structs for when it makes more sense to have
> distinct copies.
That implies all structs should have copy semantics. I'm not sure
whether this is good or bad, I'm just saying :o).
Andrei
More information about the Digitalmars-d
mailing list