[WIP] Add rcarray (using __RefCount)#2646
Conversation
|
What happens if you slice a |
|
454c897 to
2797ba5
Compare
| * Returns: | ||
| * an empty `rcarray` | ||
| */ | ||
| auto make(Q : rcarray!T, T)(size_t initialCapacity = 0) |
There was a problem hiding this comment.
This factory function is at the module level. The reason for this is that this way one is able to specify the mutability qualifier, without repeating the name of the struct (i.e. auto ia = make!(immutable rcarray!int); instead of auto ia = rcarray!int.make!(immutable rcarray!int);). This does pollute the module and complicates selective imports.
The alternative is to simply not allow construction of const/immutable arrays through a factory function. That way, the factory function can be moved into the type (and optionally renamed, giving e.g auto a = rcarray!int.empty;). This might be fine, as I can't think of many legitimate use cases of constructing empty const/immutable arrays anyway.
(Sadly, a factory function is necessary to be able to create empty rcarrays without having to explicitly specify the initial capacity. We can't use the default constructor, as that would leave __RefCount, which allocates memory in its constructors, uninitialised).
There was a problem hiding this comment.
Hmm wouldn't the name be confusing for people who know about stdx.allocator (https://dlang.org/phobos/std_experimental_allocator.html#make)?
What do other people think about the name?
There was a problem hiding this comment.
We already have https://dlang.org/phobos/std_container_util.html#.make. I don't think it would be particularly confusing. That said, I still don't know if it's the best option.
| * Returns: | ||
| * an empty `rcarray` | ||
| */ | ||
| auto make(Q : rcarray!T, T)(size_t initialCapacity = 0) |
There was a problem hiding this comment.
Hmm wouldn't the name be confusing for people who know about stdx.allocator (https://dlang.org/phobos/std_experimental_allocator.html#make)?
What do other people think about the name?
Squashed commit of the following: commit ee96796 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Fri Mar 29 15:16:46 2019 +0200 Fix invalid support bug commit 8e2a813 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Thu Dec 6 18:21:57 2018 +0200 Make array usable in betterC commit ab1eef7 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Dec 4 16:29:00 2018 +0200 Leave bounds checking to underlying T[] support commit 82b1bbc Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Dec 4 16:28:04 2018 +0200 Mark isShared as the msb inside the ref count commit 4410979 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Thu Nov 29 14:14:54 2018 +0200 Use version (CoreUnittest) for stats allocator commit d0a8ae5 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 27 13:52:22 2018 +0200 Refactor idup commit a144462 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 27 13:50:26 2018 +0200 Refactor dup commit 97db995 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 26 17:24:30 2018 +0200 Rename to `rcarray` commit 4ac6812 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 26 17:15:46 2018 +0200 Comply with D_NoBoundsCheck commit 5d98a65 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 26 16:26:41 2018 +0200 DStyle: Add space between version ( commit 68191fa Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 26 16:17:44 2018 +0200 Make `each` compatible with Phobos' `each` commit 65c0fde Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 20 21:05:08 2018 +0000 Change from labels to inline access specifiers commit 5fa4cbd Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 20 16:48:24 2018 +0200 Remove array's internal range API commit 025b50f Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 20 15:25:05 2018 +0200 Make global symbols private commit 86ea7ed Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 20 14:53:57 2018 +0200 Implement opEquals and remove global equals fn commit 60b3143 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 20 14:27:06 2018 +0200 Allow toHash to infer safety commit 815942b Author: Eduard Staniloiu <edi33416@gmail.com> Date: Tue Nov 20 14:23:22 2018 +0200 Remove obsolete ctor commit 89b48a6 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 12 22:01:55 2018 +0000 Remove range deps commit d9c02b0 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 12 15:34:10 2018 +0000 Rename internal fields commit 6642656 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 12 15:07:28 2018 +0000 Import Unqual from core traits commit 039483d Author: Eduard Staniloiu <edi33416@gmail.com> Date: Mon Nov 12 15:05:52 2018 +0000 Make length behave as builtin array's commit a206494 Author: Eduard Staniloiu <edi33416@gmail.com> Date: Sun Nov 11 21:46:11 2018 +0000 [WIP] Add @nogc array
This commit fixes rcarray for class types, storing class references (i.e. not class states). The previous code (both in dlang#2348 and in https://github.com/dlang-stdx/collections) was broken and allocated memory for a class *state* but used the memory to store *references*.
Found with ASan (LDC)
|
RC requires __mutable to be implemented. There is a reference to this PR here: https://issues.dlang.org/show_bug.cgi?id=23071 |
This PR adds an array/slice type (
rcarray!T) that behaves like built-in arrays (T[]) but manages its own memory through reference counting.The implementation is largely based on #2348 but uses the upcoming
__RefCountstruct for reference counting. (This PR contains the__RefCountcommits as they aren't merged yet, but please review them separately: #2608.)Left to do: