How usable is the D language without a garbage collector?

ryuukk_ ryuukk.dev at gmail.com
Fri Jul 15 14:55:45 UTC 2022


On Friday, 15 July 2022 at 09:27:51 UTC, LinguisticMystic wrote:
> I'm looking for a modestly mature language to be a C++ 
> replacement for my hobby needs. D seems to be a good one as it 
> ticks all the boxes of C++ while fixing most (all?) of its 
> flaws. However, what confuses me is the fact that D has a 
> garbage collector. My necessary requirement is that the runtime 
> should not include any such thing. And D does have some sort of 
> @nogc switch. My question is, how usable is the scenario of 
> GC-free programs in reality? Does the switch apply globally, so 
> that the compiled binary is free from GC code? How many 
> essential libraries can work without GC? Is it better for me to 
> look elsewhere if I don't want GC?
>
> Thanks for your clarifications!

It is perfectly usable without a GC

You have access to malloc/free from libc and also allocators, so 
you can do what ever you want!

I am working on an online RPG targeting WASM without touching the 
GC at all, no RAII (thanks to scope guards aka defer, 
scope(exit)), no exceptions and it's been super smooth

- game server

- login server

- master server

- front end

- database stuff

D is a very pragmatic language, i still use the GC for tooling 
projects and the deployment scripts where the GC doesn't have any 
impact at all, it was very useful to have even thought not 
necessary

https://www.kdom.xyz/

If you don't want the GC then you know what you are doing you 
don't want to deal with 3rd-party anyways since they can mess up 
your memory allocation strategy

You can consume C/C++ code with D, so you can consume their 
entire ecosystem with ease

I consume GLFW on desktop, Freetype for fonts, OpenGL/OpenAL for 
gpu/audio and PostgreSQL for the database, they are all C 
projects and the integration is super smooth

And there are lot of people around developing D libraries that 
are @nogc compatible


More information about the Digitalmars-d mailing list