On 28-04-2012 23:20, Adam D. Ruppe wrote:
On Saturday, 28 April 2012 at 18:48:18 UTC, Walter Bright wrote:
What's your list?

I think most the responses to this thread are insane.

But, there is one thing I don't think D needs: new.
I'm pretty sure it could be done in the library now
that we have robust templates, which I think would open
up some nice things.

Suppose:

module std.typecons;
NotNull!T new(T, Args...)(Args args) {
return assumeNotNull(core.gc.new!T(args));
}

module core.gc;
T new(T, Args...)(Args args) {
// implement the new we know now
}



And so on, then you could get new allocators
just by changing which module you import new from.



We could kinda sorta do it now, but it wouldn't be
as consistent, and of course, the name "new" is unavailable.

OK, so while in general I agree that 'new' shouldn't be tied to the GC by default, I don't think your example of swapping allocators through imports is a good idea at all. The reason is simple: More often than not, it never *is* as simple as just changing an import. Some allocators use stack allocation, some use C heap allocation, some use the druntime GC, some use the libgc library, ... All of these need different treatment of the allocated memory, so I don't think there is much to be gained here.

--
- Alex

Reply via email to