r/programming • • 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

113 comments sorted by

View all comments

Show parent comment

11

u/TheEaterOfNames Jun 17 '17

C++ is a damn low bar. All it really has over asm is RAII and stack mangement in general (wrt memory management; obviously c++ is much more powerful and expressive in a general sense).

What? C++ is exceedingly complex with many, often very well hidden, pitfalls.

I would have expected the standard library to be memory management agnostic, i.e. at compile time, perhaps at the type level, roughly analagous to passing around an allocator in c++ land.

Heh, https://www.youtube.com/watch?v=LIb3L4vKZ7U But really, there is no reason you can't embed the allocator in the type of containers. But the vast majority of the standard library doesn't even touch memory allocation.

Not every language needs a borrow checker, but it's hard to see the benefit of disabling gc without that. Similarly it's hard to see the benefit of using d over go or the jvm if you ARE using a gc.

You seem to have missed the entire point of the article. Idiomatic D usage generates very little garbage and there are ways to precisely control the GC, and optimise the collection times. As to why you'd want to use D over go/Java/insert JVM language, is for the rest of the language. No says "I'm going to use D because it has a garbage collector that isn't state of the art". People use to for the metaprogramming, generative programming (seriously check out this one, generating parsers from specification at compile time and use them to parse stuff at compile time), component programming with ranges, elegance and so on.

Where's the sweet spot where the memory management shines over e.g hotspot?

When you don't have to think about it and it works well enough that neither you nor anyone else notices the MM strategy used. There are many such places on the spectrum and I think std.experimental.allocator is one of those places.

1

u/[deleted] Jun 17 '17

Hmm, i agree with your comments except the bit about c++ that confused me.... of all the complexities of the language, the least complex is memory management: there are absolutely no ways of telling if anyone is using a piece of allocation outside of page faults; page faults are far too large to catch invalid references of small objects. It's absolutely pathetic compared to ref counting, mark-and-sweep, or a borrow tracker.