rc 0.0.2
Reference counting
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Reference counting
simple using
import rc;
class A { }
class B
{
A a;
this( A a )
{
this.a = a;
RC.incRef(a);
}
~this()
{
RC.decRef(a);
}
}
void main()
{
auto a = rcMake!A;
auto b = rcMake!B(a);
import std.stdio;
writeln( RC.refCount(a) ); // 2
}
using arrays and wraps
import rc;
class A {}
void main()
{
import std.stdio;
RCObject!A obj;
{
RCArray!(RCObject!A) tmp;
{
auto arr = rcMakeArray!(RCObject!A)(4);
foreach( ref a; arr )
a = rcMake!A;
assert( arr[0].refCount == 1 );
assert( arr[1].refCount == 1 );
assert( arr[2].refCount == 1 );
assert( arr[3].refCount == 1 );
tmp = arr[1..3];
assert( arr[0].refCount == 1 );
assert( arr[1].refCount == 2 );
assert( arr[2].refCount == 2 );
assert( arr[3].refCount == 1 );
obj = arr[2];
assert( arr[2].refCount == 3 );
}
// objects in arr[0] and arr[3] are deleted
assert( tmp[0].refCount == 1 );
assert( tmp[1].refCount == 2 ); // second in `obj`
}
// now delete arr[0]
assert( obj.refCount == 1 );
}
- 0.0.2 released 8 years ago
- deviator/rc
- MIT
- Copyright © 2016, deviator
- Authors:
- Dependencies:
- none
- Versions:
-
0.0.2 2016-Jun-26 0.0.1 2016-Jun-26 ~master 2016-Jun-26 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
71 downloads total
-
- Score:
- 0.9
- Short URL:
- rc.dub.pm