Opportunities for D

Remo via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 8 16:18:49 PDT 2014


On Tuesday, 8 July 2014 at 22:56:56 UTC, bearophile wrote:
> Remo:
>
>> unique_ptr<T> is helpful in 90% of the time.
>> shared_ptr<T> is necessary in may be another 9%.
>> Memory pool is helpful in another cases.
>> And only in 0.1% case GC is really needed. :)
>
> Are you forgetting the RefCount?

shared_ptr<T> uses reference counting.
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/shared_ptr.htm

> But I use D because it has a GC and it doesn't look like C++, I 
> am not writing device drivers or an operating system, I am OK 
> with a language less efficient than C++ if it gives easier to 
> write code, more compact code, less noisy code, much less 
> bug-prone code.
>

I do not saying that GC is always bad.
The future C++ standard will get GC too.
It is strange but some peoples (not C++ programmers) think that D 
looks too much like C++ and this is bad :)
For this is advantage that D looks a bit like C++ and can 
interact/work with C/C++ !

I like a lot of D features.
Templates for example are probably easier to write in D as in 
C++, but I still do not have problems with them in both languages.

So if I want to write a simple tool then I would use D2 instate 
of C++.
But everything (like a 3D Renderer) that need to be as fast as 
possible can still only be written in C++.

> In C++11 you have over-engineered lambdas because there is no 
> GC, D GC rely on the GC and sometimes allocate on the heap. I 
> don't want the very bad syntax and semancits of C++ lambdas in 
> D. Closures and lambdas are quite common in the D code I write.

Well yes may be the lambdas syntax in C++ is not the best but it 
is still great addition to the language.

> How do you concatenate built-in arrays without GC? And so on...

The same way one do this in C++ ?
Copy second array at the end of the first one.
If there is not enough free space in the fist array (a) then.
Allocate new array bigger as size of (a+b) and copy array (a) and 
(b) to the new memory, then free old memory.
This work reasonable well for std::vector<T> .

And how this will be done with GC ?

>> So how about memory pool for D ?
>> It there already one ?
>
> Andrei is working a lot on them. They look very good.

Is the code public already ?

> Bye,
> bearophile



More information about the Digitalmars-d mailing list