digitalmars.D - D plan to do RAII(Resource Acquisition Is Initialization)?
- FrankLike (2/2) Feb 21 2015 RAII(Resource Acquisition Is Initialization) is a good thing,will
- weaselcat (6/8) Feb 21 2015 RAII in D is handled by structs.
- Olivier Pisano (11/13) Feb 21 2015 It's already here :
RAII(Resource Acquisition Is Initialization) is a good thing,will D plan to do it?
Feb 21 2015
On Saturday, 21 February 2015 at 10:06:26 UTC, FrankLike wrote:RAII(Resource Acquisition Is Initialization) is a good thing,will D plan to do it?RAII in D is handled by structs. It becomes a bit tricky when you want class semantics with RAII, but can be handled by wrapping the class in a struct I suppose. The unique and refcounted implementations would help with this, but they are lacking.
Feb 21 2015
On Saturday, 21 February 2015 at 10:06:26 UTC, FrankLike wrote:RAII(Resource Acquisition Is Initialization) is a good thing,will D plan to do it?It's already here : import std.stdio; struct Test { ~this() { writeln("RAII"); } } void main() { Test t; // prints "RAII" when goes out of scope }
Feb 21 2015
On Saturday, 21 February 2015 at 18:30:18 UTC, Olivier Pisano wrote:On Saturday, 21 February 2015 at 10:06:26 UTC, FrankLike wrote:RAII(Resource Acquisition Is Initialization) is a good thing,will D plan to do it?It's already here : import std.stdio; struct Test { ~this() { writeln("RAII"); } } void main() { Test t; // prints "RAII" when goes out of scope }
Feb 21 2015
On Saturday, 21 February 2015 at 18:30:18 UTC, Olivier Pisano wrote:On Saturday, 21 February 2015 at 10:06:26 UTC, FrankLike wrote:He's maybe talking about reference counting because "owning" the resources is very faisable and simple (non gc objects are constructed in this() and destructed in ~this(), but the problem happends when you escape the owned reference as a raw pointer. At a time it may become dangling or even freed by another entity, e.g not the one which has initialized the thing. The first reply is clearly about this (when weaselcat said "It becomes a bit tricky when you want class semantics with RAII"), because std RC is not for classes.RAII(Resource Acquisition Is Initialization) is a good thing,will D plan to do it?It's already here : import std.stdio; struct Test { ~this() { writeln("RAII"); } } void main() { Test t; // prints "RAII" when goes out of scope }
Feb 21 2015