is struct delete deterministic? (cf used in Unique)

weaselcat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 7 16:02:59 PST 2015


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.


More information about the Digitalmars-d-learn mailing list