deprecated delete and manual memory management

Daniel Gibson metalcaedes at gmail.com
Wed Apr 27 13:28:07 PDT 2011


Am 27.04.2011 22:13, schrieb so:
>> 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 :)

It'd create template bloat and uglier syntax (expecially confusing for
people coming from about any other popular OO language) for a really
common, standard feature.
These drawbacks are acceptable for custom allocation and other stuff the
average user shouldn't care about, but not for an elemental feature like
"new".

Cheers,
- Daniel


More information about the Digitalmars-d mailing list