eliminate new operator paraphernalia
Michel Fortin
michel.fortin at michelf.com
Sun Feb 14 14:15:34 PST 2010
On 2010-02-14 15:41:30 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
> Michel Fortin wrote:
>>
>> Hum, what's the syntax for placement delete?
>
> There is no need for placement delete. There will be a function clear()
> in object.d that only calls the destructor. (That is needed
> regardless.) You can carry deallocation with your own API functions.
What's the point in wasting a function name only to call the
destructor? Why not just allow "object.~this()"?
Also, if you really want to put an object back in it's initial state,
you could call both the destructor and the constructor. Anything else
is going to break the object's invariant. I think it's best to leave
breaking the object's invariants to a special syntax, hence
"object.~this()".
>> So why remove custom allocators? Those can be useful to catch all
>> allocations of a specific class in an existing code base and improve it
>> for some specific needs without having to change code everywhere. I'd
>> rather see that better generalized (we talked about making 'new' a
>> template earlier).
>
> There are many problems with custom allocators. They hook the syntax
> and do something that's unbecoming. new T must place T on the
> garbage-collected heap, period. That gives the guarantee that the
> object has infinite lifetime and therefore dependable behavior. If the
> same syntax can be used to implement various other semantics, you can't
> count on anything in generic code.
Well, I agree that new should have dependable semantics. I disagree
about it being always from a GC-allocated block. There are other ways
to create infinite lifetime behaviour, like a smart pointer. Of course
you can't do that with 'new' as it stands today because you can't make
it return something else than a crude pointer. That's what need to be
fixed I think.
You could say that having placement-new fixes that problem, and in a
way it does because it allows you to create what I've described as a
separate function. Except you have to use a different syntax to create
the object which makes things less transparent (especially with generic
code).
Also, having placement-new and regular-new share the almost same syntax
isn't a good way to say that 'new' has dependable semantics. I think
there is a better syntax for calling the constructor: "object.this()".
>> Also, why remove anonymous classes?
>
> Walter thinks we need to keep them.
Is that your reason for wanting them removed? :-)
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list