eliminate new operator paraphernalia
grauzone
none at example.net
Mon Feb 15 04:27:46 PST 2010
Andrei Alexandrescu wrote:
> Michel Fortin wrote:
>> 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()"?
>
> You might want to clear an int etc. for which it's unclear whether the
> above should work.
>
>> 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()".
>
> Yah, clear destroys and then fills with .init.
How is filling with .init not a waste of time?
Now I'm not really sure, but I'm going to guess... you think it's safer?
I don't think "reusing" objects is safe memory management. OK, you
probably could still sandbox such a program, and there will never be
segfaults (except null pointer accesses). But the user could still have
references to "dead" objects. Or even worse, "false" objects, that have
been reinitialized even though some other parts of the program needed
the old object. There, you have the same mess as with traditional manual
memory allocation.
As a D user, I'm kindly asking for actually safe memory management
primitives, that are more efficient than the old GC.
By the way, what does "paraphernalia" mean?
> Andrei
More information about the Digitalmars-d
mailing list