| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
February 21, 2015 D plan to do RAII(Resource Acquisition Is Initialization)? | ||||
|---|---|---|---|---|
| ||||
RAII(Resource Acquisition Is Initialization) is a good thing,will D plan to do it? | ||||
February 21, 2015 Re: D plan to do RAII(Resource Acquisition Is Initialization)? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to FrankLike | 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.
| |||
February 21, 2015 Re: D plan to do RAII(Resource Acquisition Is Initialization)? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to FrankLike | 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
}
| |||
February 21, 2015 Re: D plan to do RAII(Resource Acquisition Is Initialization)? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Olivier Pisano | 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
> }
| |||
February 21, 2015 Re: D plan to do RAII(Resource Acquisition Is Initialization)? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Olivier Pisano | 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
> }
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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply