ref?

Jerry Quinn jlquinn at optonline.net
Sun Feb 15 09:09:11 PST 2009


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.

Jerry




More information about the Digitalmars-d mailing list