www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - GC and RC

reply KnightMare <black80 bk.ru> writes:
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.

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:
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.

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: 
- how can be used different allocators? what exactly they are: 
struct* or interfaces? with what fields? with function ptrs to 
Jun 11 2019
next sibling parent KnightMare <black80 bk.ru> writes:
On Tuesday, 11 June 2019 at 20:28:51 UTC, KnightMare wrote:
 - will be created utility that automatically converts the 
 GC-code to nongc? arrays to rcarrays etc.
- will the compiler be split into 2 parts? compiler can generate code from (1) to (2) for nogc automatically when it knows rc-types and how handle it. can remove unnecessary addref/release for params, for returns probably. pro: user source code can be same. generated code depends only from compiler version or compiler option - GC or RC. (can be same source for RT?)
Jun 11 2019
prev sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
Your over thinking it.
RC is a wrapper struct around a bit of memory.

It won't require compiler changes and it could be backed by GC for 
allocation (I use RC for system sensitive handles like windows even 
though it is GC still).
Jun 11 2019