RFC: reference counted Throwable

Uranuz via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 20 01:42:50 PDT 2014


I'm quite a noobie in memory models but from position of user of 
D language I have some ideas about syntax of switching between 
memory models. I think that having everywhere declarations using 
wrapper structs (like RefCounted) is not very user-friendly. But 
still we need some way to say to compiler how we want to do 
memory management. I have read tutorial about Rust language. It 
looks not very clear for me, but I like the idea that type of 
memory management is included in variable declaration.

Intead of wrapper struct like scoped!A or RefCounted!A we could 
declare variables with annotations (attributes in D) to say what 
memory model we want to use. Compiler should understand this 
annotation and create some code for memory management. I thing 
it's possible to declare some interface (maybe struct with 
compile-time duck typing) to support some user-defined memory 
models or modifications of basic (implemented in a language) 
memory models.

Why I am saying about annotations? Because we can annotate some 
function, class or just block at the module scope that should use 
some sort of memory management and compiler will create 
corresponding code. In that case we don't need to put wrapper 
struct around all variables that use ref counting. We just 
annotate some function or class declaration as ref-counted and 
that's it!

It's just a concept of what I like to see in the language design 
of D in future)) Of course there are a lot of problems in a 
practice.

Also I think that we shouldn't impose some way of memory model to 
programmer and let him choose his approach but syntax should be 
simple and clear as much as it could be. Also some defaults 
should be for most common cases and for *novice* users of D.

Waiting for critic or thoughts!!!))


More information about the Digitalmars-d mailing list