What's the go with the GC these days?

Neia Neutuladh neia at ikeran.org
Sun Jan 6 04:52:31 UTC 2019


On Sat, 05 Jan 2019 19:46:22 -0800, Walter Bright wrote:
> On 1/5/2019 3:12 PM, Neia Neutuladh wrote:
>> The Boehm collector is more advanced than D's GC. It's (at least
>> optionally) generational with write barriers.
> 
> Hmm, how does the Boehm collector insert write barriers?

The docs say it "provides incremental and generational collection under 
operating systems which provide the right kind of virtual memory support." 
The source code says they're using mprotect on most posix systems, 
vm_protect on OSX, and something on Windows.

The only other way I know of to implement a write barrier is to insert 
some code on every pointer write. GC-as-a-library would require you to use 
their pointer type instead of the builtin, and I expect most C++ devs 
would rather just use a reference counting pointer type instead.

> Back in the 90's, I implemented a collector that did write barriers by
> setting the page to read-only. When a write to it was executed, the
> resulting seg fault was captured, the write was logged, and the page was
> set to read-write.
> 
> It was a fabulous idea, but the problem was it was SLOWER! The operating
> system's dealing with seg faults and changing write permissions was
> execrably slow.

Either the speed has improved, or they're just eating the time cost.

The other side effect is that you (and the GC) have to be very careful 
about replacing other segfault handlers.


More information about the Digitalmars-d mailing list