SImple C++ code to D

Alexandre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 15 07:49:34 PDT 2014


Oh!
I used the RefCounted because this:
"The proposed C++ shared_ptr<>, which implements ref counting, 
suffers from all these faults. I haven't seen a heads up 
benchmark of shared_ptr<> vs mark/sweep, but I wouldn't be 
surprised if shared_ptr<> turned out to be a significant loser in 
terms of both performance and memory consumption.

That said, D may in the future optionally support some form of 
ref counting, as rc is better for managing scarce resources like 
file handles. Furthermore, if ref counting is a must, Phobos has 
the std.typecons.RefCounted type which implements it as a 
library, similar to C++'s shared_ptr<>."

I found that in this link: 
http://dlang.org/faq.html#reference-counting

On Tuesday, 15 July 2014 at 14:46:01 UTC, bearophile wrote:
> Alexandre:
>
>> 	RefCounted!(DWORD) addr;
>
> I think RefCounted is for advanced usages in D :-)
>
>
>> template Wrap(T)
>> {
>> 	struct Wrap
>> 	{
>> 		T val;
>> 		this(T val){val = val;}
>> 	}
>> }
>
> Simpler:
>
> struct Wrap(T) {
>     T val;
>     this(T val_) { this.val = val_; }
> }
>
>
> Or just:
>
> struct Wrap(T) { T val; }
>
> Bye,
> bearophile



More information about the Digitalmars-d-learn mailing list