What are the prominent upsides of the D programming language?

Elronnd elronnd at elronnd.net
Wed Sep 23 07:58:05 UTC 2020


On Wednesday, 23 September 2020 at 04:04:04 UTC, mw wrote:
> there is a particular set of objects which takes the majority 
> of memory consumption of the program, and even after I 
> carefully removed all the reference after the object is no 
> longer used, the program still use lots of memory because GC 
> collection is un-predictable, both in terms of timing and 
> efficiency.
>
> Then I decided to do manual core.memory.GC.free just for that 
> particular objects, (it was not very easy in a multi-threaded 
> program to make all the logic right, but eventually I got it 
> done). And the resulting program now only use ~10% of the 
> memory it used to use.

I recommend experimenting with 'scope' and seeing if it will work 
in place of manually freeing.  If that doesn't work, then I 
recommend using libc's malloc and free instead of GC.malloc and 
GC.free.  Reason: you avoid increasing the GC's heap size.  
https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation has a good example of using std.emplace to do this.  (Note that you only need to use GC.addRange if the objects you allocate themselves point to other objects.)


> I think this flexibility to mix GC & manual memory management 
> is very unique in D. Actually I'm not sure if it can be done in 
> other languages at all.

Take a look at cone and its gradual memory management - 
https://pling.jondgoodwin.com/post/gradual-memory-management/


More information about the Digitalmars-d mailing list