std.container and classes
Steven Schveighoffer
schveiguy at yahoo.com
Mon Dec 19 07:44:20 PST 2011
On Sun, 18 Dec 2011 01:15:40 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> On 12/17/11 7:52 PM, Jonathan M Davis wrote:
>> The only reason that I can think of to use a reference-counted struct
>> instead
>> of a class is becuse then it's easier to avoid the GC heap entirely.
>> Almost
>> all of a container's memory is going to end up on the heap regardless,
>> because
>> the elements almost never end up in the container itself.
>
> Being on the heap is not the main issue. The main issue is the data
> becoming garbage once all references are gone.
This whole thread of discussion is somewhat more complicated than it has
to be.
A ref-counted type is implemented via a reference to allocated data. That
data can be a class instance or a struct pointer.
Using a reference style struct just introduces problems you don't have to
worry about with a class. It gains you nothing except having to crowbar
the language into believing your struct is really a reference type.
And that's really hard to do.
-Steve
More information about the Digitalmars-d
mailing list