On 07/13/2010 01:12 PM, Vladimir Panteleev wrote:
On Tue, 13 Jul 2010 18:30:26 +0300, Andrei Alexandrescu
<[email protected]> wrote:

I agree deprecation shouldn't be taken lightly, but delete is not a
fundamental operator - it could and should be defined at most as a
simple function.

delete is the antipod of new. With this logic, I don't see why new
shouldn't be replaced with a function as well - after all, all it does
is allocation and initialization, as opposed to delete's destruction and
deallocation.

Not quite. New is different because it is a primitive - it can't be implemented as a function (well it could if it user placement new, but we're back to square one). In contrast, delete already knows the type of the object it's destroying and can call the destructor manually so it is easy to implement as a regular function.

Anyway, I'd be glad to provide a function that calls malloc() and then the emplace(), and also a function that calls the destructor and then free(). But manual deletion has no business in the garbage collected heap. That currently druntime provides it is an accident caused by the current implementation; most GC's cannot provide efficient manual reclamation. And they shouldn't anyway.

(There's a longer discussion underneath this concerning what memory really is and what GCs really are and do.)


Andrei

Reply via email to