std.container and classes
Jonathan M Davis
jmdavisProg at gmx.com
Tue Dec 20 23:29:47 PST 2011
On Wednesday, December 21, 2011 08:07:23 foobar wrote:
> I disagree with the above conclusion. you conflate two issues
> that are orthogonal:
> a. value vs. ref semantics which is already seemed to be decided
> in favor of the latter and hence classes. b. memory and lifetime
> management
>
> The containers should allow for (disregard the specifics of the
> syntax):
>
> Container a = new(SharedMemAllocator) LinkedList();
> Container b = new(MallocAllocator) LinkedList();
> Container c = new(GC) LinkedList();
>
> When adding an item to the above containers the relevant
> allocator will enact its policy about intermixing with other
> allocators - by default the item will be copied if it comes from
> a separate allocator. I don't see anything here that forces the
> use of structs instead of classes.
And if they're classes and not managed by the GC nor in a struct which manages
their lifetime, how are they going to be freed? Does the user have to
explicitly free them themselves? How is that better than using a ref-counted
struct?
And no, using reference semantics does _not_ require classes. A class is just
the easiest way to get reference semantics. It doesn't necessarily mean that
it's the best way. That depends on the context.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list