This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Closed
Conversation
aG0aep6G
reviewed
Aug 26, 2019
Contributor
Author
Contributor
|
As far as I can tell, these containers are not They allow obtaining references to their elements, and they don't manage to do it Examples where references to elements outlive their containers (i.e. they become dangling): ref int slice() @safe
{
auto s = __rcslice!int(1);
s[0] = 42;
return s[0];
}
ref int array() @safe
{
rcarray!int a;
a ~= 42;
return a[0];
}
ref int slist() @safe
{
rcslist!int s;
s.insertFront(42);
return s.front;
}
ref int map() @safe
{
rcmap!(int, int) m;
m[0] = 42;
return *(0 in m);
} |
Contributor
|
RC requires __mutable to be implemented. There is a reference to this PR here: https://issues.dlang.org/show_bug.cgi?id=23071 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This PR adds four
@safe @nogc @nothrowreference counted data structures tocore.experimental:The slice in this PR differs from
__rcptr!T(#2690) by using intrusive reference counting instead of the refcount being external to the object, increasing performance. This also means we can safely callfreeon the pointer because we always allocate memory ourselves withmalloc.Sadly, we're still stuck with using atomics for the reference count (see discussion here: #2679 (comment)). I believe this could only reasonably be solved by changing the
immutable=>sharedconversion rules. This would probably break a lot of code (and obviously requires a DIP) and I'm not sure what the deprecation process would look like. I'll start a thread on the NG soon to discuss this issue further.(The hash map does not yet support (non-empty) creating immutable instances. For now, one should be able to use the same idiom that can be used for the built-in ones: https://dlang.org/spec/hash-map.html#runtime_initialization.)