GC and RC
KnightMare
black80 at bk.ru
Tue Jun 11 20:28:51 UTC 2019
Lets discuss two worlds: GC and RC.
I want to know how it will be work for self-education. probably
others will be interested too.
(1)
int[] findSpanWithMaxSum( int[] arr ) { ... return
arr[someBeg..someEnd]; }
this code will work with GC and with nogc for static arrays
let's rewrite it for nogc:
(2)
auto/*rcspan!int*/ findSpanWithMaxSum( inout ref rcarray!int arr )
{ ... return arr[someBeg..someEnd]; }
where rcspan is struct{.rcarray, .offset, .length} that can
handle RC.
by ref coz don't needed addref/release. atomic can be expensive.
RC-library:
rcarray!T // and strings
// multidimensional arrays?
// static rcarray? rcspan should be compatible with it too.
rcspan!T // usual slice{.ptr, .length} shouldn't be compatible
with RC.
rcmap!(K,V) // rcset!K?
rc!T // smart-ptr
what more?
questions and assumptions:
- RC is atomic for shared vars
- what with weak ptrs?
Form { Label{@weak .parent}; Button{@weak .parent}; }
no need addref/release for .parent. ~Form invokes .release for
children. what the type of .parent better: some rcweak!Form or
raw Form*?
- how will work ranges for RC-types?
- will be created utility that automatically converts the GC-code
to nongc? arrays to rcarrays etc.
- can be added classes with C++new/emplace/destroy semantics?
right now I've got error for scoped!ClassA (class obj at stack):
C:\..\..\import\std\conv.d(4489): Error: No implicit garbage
collector calls allowed with nogc option enabled:
_d_array_slice_copy
- how can be used different allocators? what exactly they are:
struct* or interfaces? with what fields? with function ptrs to
alloc/free?
More information about the Digitalmars-d
mailing list