deprecated delete and manual memory management

Timon Gehr timon.gehr at gmx.ch
Tue Apr 26 14:43:51 PDT 2011


> On 26.04.2011 21:48, Benjamin Thaut wrote:
>
>> I still don't understand why the delete operator is deprecated completely.
>
>  Me too, to be honest. Any pointers to this discussion? Custom new/delete ops >
could be *very* useful (and natural) for system-level programming (kernels & >
co), also for just manual MM (which is useful sometimes).
>
> /Alexander

But you understand why it is deprecated for GC memory?

The main thing to note is that the semantics of C++ 'new' and D 'new' are rather
different.
D 'new' performs allocation on the GC heap by default. The only sane overloads of
'new' would therefore allocate the object on a custom GC heap, which you never
want to do. So there is absolutely no way to overload the 'new' operator
meaningfully inside the D language. The argument for removing 'delete' overloading
is trivial after taking that into consideration.

You can still create custom allocators by the means of template functions. (I do
not think this is optimal though because they duplicate code that needn't be) They
feel a little bit less natural though, which is not a problem, since in D, custom
allocators and manual memory management in general, _are_ less natural.

Benjamin Thaut wrote:
> I still don't understand why the delete operator is deprecated
> completely. It could be defined, that it is only useable if the new and
> delete operator have been overloaded in the class or struct that is
> tried to be deleted.
hich
You don't gain anything by overloadable new/delete in D, because you cannot use
the feature to quickly patch in a custom allocator to existing code as possible in
C++ as a means of optimization. (this binds that allocator to a specific type,
which does not make much sense in other context) I agree that new/delete is nicer
to look at than the template-based version, but as discussed above, that does not
really help.

Timon


More information about the Digitalmars-d mailing list