deprecated delete and manual memory management

so so at so.so
Wed Apr 27 13:13:20 PDT 2011


> One thing that is perhaps obvious, but eludes me; when dropping the
> delete-operator, are there any obvious reason to not also drop the
> "new" keyword? ("new" is a fairly good method/variable name, if
> nothing else)
>
> I could see two possible alternatives:
>
> Global (and defined-by-default) template new!(Type): (as suggested
> elsewhere in this thread by so)
>   This is very close to the current situation, but makes it possible
> to use as a method-name, and clearly states there's nothing "magic"
> about it.
>
> Explicit Allocator, such as GC.new!(Type).
>   Would have the benefit of clearly showing who did the allocation,
> and would map nicely to other allocators. (Malloc.new/free!(T)!(T)).
>
>   It would also allow library-methods that might allocate instances,
> take an allocator as an optional template argument. I.E.
>     auto obj = dict.createObject("key");
>   OR
>     auto obj = dict.createObject!(Malloc)("key");
>     scope(exit) Malloc.free(obj);
>
> Possibly an obvious bad idea, but I haven't seen it discussed?
>
> Regards
> / Ulrik

With the deprecated "delete", custom allocators and such i don't see much  
of a reason other than saving an "!" (actually we don't save a char here,  
" " also a char :) ), and "()" if you are calling the default constructor.  
I don't consider these points negative, quite contrary, you just got rid  
of an arcane syntax.

It is understandable for C++ has it. If nothing else, the lack of many  
basic features (maybe the reason of this syntax).

Rather then removing all together, i would drop them from language and go  
for a library solution, if there is an obvious blocker, i also fail to see  
it :)


More information about the Digitalmars-d mailing list