How to use D without the GC ?

Steven Schveighoffer schveiguy at gmail.com
Tue Jun 11 16:54:44 UTC 2024


On Tuesday, 11 June 2024 at 13:00:50 UTC, Vinod K Chandran wrote:
> Hi all,
> I am planning to write some D code without GC. But I have no 
> prior experience with it. I have experience using manual memory 
> management languages. But D has so far been used with GC. So I 
> want to know what pitfalls it has and what things I should 
> watch out for. Also, I want to know what high level features I 
> will be missing.
> Thanks in advance.

I could answer the question directly, but it seems others have 
already done so.

I would instead ask the reason for wanting to write D code 
without the GC. In many cases, you can write code without 
*regularly* using the GC (i.e. preallocate, or reuse buffers), 
but still use the GC in the sense that it is there as your 
allocator.

A great example is exceptions. Something that has the code `throw 
new Exception(...)` is going to need the GC in order to build 
that exception. But if your code is written such that this never 
(normally) happens, then you aren't using the GC for that code.

So I would call this kind of style writing code that avoids 
creating garbage. To me, this is the most productive way to 
minimize GC usage, while still allowing one to use D as it was 
intended.

-Steve


More information about the Digitalmars-d-learn mailing list