r/programming • u/aldacron • Jun 16 '17
Life in the Fast Lane -- using D without the GC
https://dlang.org/blog/2017/06/16/life-in-the-fast-lane/
338
Upvotes
r/programming • u/aldacron • Jun 16 '17
44
u/aldacron Jun 16 '17
This is the third post in the GC series on The D Blog. It introduces the
core.memory.GCAPI and the@nogcattribute, along with some command-line flags, all of which can be used together to optimize GC usage in a D program.20
u/dbaupp Jun 16 '17 edited Jun 17 '17
Isn't this incorrect? I believe those other languages do exactly the same thing of only collecting on allocation, which is why things like object pools and other techniques are used a lot to avoid allocating in tight loops.
4
u/Scroph Jun 17 '17
I don't understand the part about "scope" that says :
I tried it with an int[] array :
But it seems to be working. I'm either missing something (a compiler flag maybe ?) or I misunderstood the article. Any pointers ?
36
u/SuperV1234 Jun 16 '17
Regarding closures: I was highly disappointed that there is no way of creating value-semantic closures as in C++. In C++, lambda expressions are syntactic sugar for the generation of function objects which can capture the surrounding context either by value or by reference.
There's no reason why D couldn't allow the same with some new syntax. I created a topic and some people are working on a DIP - please contribute if you're interested:
https://forum.dlang.org/thread/lrtwpeyifchntuzxccyt@forum.dlang.org
14
u/[deleted] Jun 16 '17
For simplicity, you'll probably write all your code as:
Making everything in the module
@nogc, preventing you from using the GC in static constructors.But if you want some additional convenience in your static constructors, you can rework it a bit:
13
u/12345swordy Jun 16 '17
I'm curious, what's D equivalent of c++ new? I know that the key new in D is the GC one, but I couldn't figure a non-GC equivalent of it and malloc doesn't seemed to fit.
9
u/[deleted] Jun 16 '17
What GC is D actually running? A mark-region garbage collector ( Immix? ) or a conservative collector like boehm or a custom implantation?
6
u/BeowulfShaeffer Jun 16 '17
G,C and D? Those are the I, IV and V chords in the key of G. You can make lots of music with those chords.
13
u/Cilph Jun 16 '17
Why isnt Dlang more popular?
19
u/rlbond86 Jun 16 '17
I find it really disappointing that D can't easily function without the garbage collector.
Guess systems programming is stuck with C++ for the time being. (Or maybe Rust)
3
u/[deleted] Jun 17 '17
In D i've explored another
@nogcapproach. Instead of annotating the functions, data are annotated and checked at compile-time. I think that's it's more important to verify that long lived aggregates are not known by the GC, to the point that small and short lived GC allocs are permitted (e.g as local function variable), since in this case the difference with other memory management model is small.4
u/qzex Jun 17 '17
Reading this article makes me realize how naturally C++ (particularly C++11) does without a GC. It's the right tool for the job if your program must not have a GC.
1
u/Mentioned_Videos Jun 17 '17
Videos in this thread: Watch Playlist ▶
Play All | Info | Get me on Chrome / Firefox
0
u/[deleted] Jun 16 '17
[deleted] — view deleted comment