-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Understanding rcarray better #320
Comments
DIP1000 isn't well implemented |
When you say I also would have thought that taking a slice with
When I modified the code from the first post as below, I was able to get some of the behavior that I was expecting, though it is not integrated into
|
Yes
import core.lifetime: move;
import mir.rc.array;
struct Foo
{
RCArray!double payload;
this(RCArray!double x)
{
payload = move(x);
}
double[] getPayloadRef() return scope
{
import mir.rc.array: rcarray;
return payload[];
}
}
void main()
{
size_t len = 5;
auto counts = len.mininitRcarray!double;
size_t i = 0;
while (i < len) {
counts[i] = i;
i++;
}
Foo foo = Foo(counts);
auto x = foo.getPayloadRef();
counts[2] = 10;
assert(foo.payload[2] == 10);
assert(x[2] == 10);
assert(counts._counter == 2);
} |
@9il Thanks for the reply. When I try to also allow it to work with a GC slice, then I get errors again.
The particular use case I was thinking about is for my work on |
maybe a GC will be good to start and then we can think about nogc api |
The current implementation is here (i.e. from before this discussion). |
@jmh530 Looking forward to the PR. (WIP status PR LGTM) Lets, don't care about an RC API for now. If we can provide a lower-level API that accepts user-provided memory, then it should be fine. A high-level API can GC-allocate memory. |
I'm a little confused by the behavior of the code below.
Foo
accepts some memory in payload, but then when I use theasRCArray
function it seems as if a copy is being made.Also, taking a slice of
counts
and passing it toFoo
does not increment the counter, even though it seems as if there is a reference back to counts (in that changingcounts
results in changes infoo
and notx
).I've also tried compiling this with -dip1000 and @safe: at the top.
The text was updated successfully, but these errors were encountered: