is struct delete deterministic? (cf used in Unique)

Timothee Cour via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 7 17:20:49 PST 2015


To clarify, I'm only asking about a struct allocated via new.
Unique!T is wrapped around a struct, but it allocates a struct T via 'new',
so my question still holds: does 'delete t' (where t is a struct allocated
via new) guarantee deterministic destruction?

I'm guessing yes, otherwise Unique would be broken, but where is that
specified in the docs?
And if delete is to be deprecated (according to the docs), what is the
correct way to do that (despite fact that Unique relies on delete).


On Sat, Mar 7, 2015 at 4:02 PM, weaselcat via Digitalmars-d-learn <
digitalmars-d-learn at puremagic.com> wrote:

> On Saturday, 7 March 2015 at 23:48:39 UTC, Timothee Cour wrote:
>
>> I'm a little confused about the following:
>> clear,delete,destroy.
>> My understanding is that clear is deprecated and delete is planned to be
>> deprecated, so we should only ever use destroy (which deterministic calls
>> the destructor but doesn't release memory).
>>
>> Unique uses delete however in the destructor. Is that still guaranteeing
>> deterministic destruction when the uniqued element is either a class or
>> struct? (ie if the destructor has a file handle resource, will it be
>> deterministically freed?)
>>
>
> structs are allocated on the stack(unless instantiated with new), and call
> their destructor when you leave their scope. Unique still guarantees
> deterministic destruction because it's wrapped around a struct, it's a
> fairly common 'D idiom' I'd say(i.e, look at how File is implemented - D's
> runtime and standard library are surprisingly well documented and easy to
> read.)
>
> I'm not sure why Unique uses delete, might just be bitrot.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150307/72eb531a/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list