News for hackers. Stuff that matters.
Re:Writing a Simple Garbage Collector in C (2020) by rurban on Sunday April 09, 2023 @05:28AM (#35501130)
Simple GC's such as this are utterly useless. For such slow stop-the-world GC's use the Boehm-Weiser libgc and nothing else.

And for a proper compacting GC there are many options, best being ravenbrook's MPS, but these require lot of source code adaptions.

Re:Writing a Simple Garbage Collector in C (2020) by matheusmoreira on Sunday April 09, 2023 @06:44AM (#35501477)
Useless? These algorithms may be simple but they're not toys. This stuff has been used in production. You can certainly improve it but it's not "useless".
Re:Writing a Simple Garbage Collector in C (2020) by rurban on Sunday April 09, 2023 @05:23PM (#35506606)
In production such a toy GC, without threading support and without register scanning? Imprecise also. How do you seperate large ints from pointers?

Brave.

Re:Writing a Simple Garbage Collector in C (2020) by webkike on Sunday April 09, 2023 @05:48PM (#35506796)
It’s a learning exercise man. Congratulations, you are very smart. FWIW, all of your questions are addressed in the article
Re:Writing a Simple Garbage Collector in C (2020) by matheusmoreira on Sunday April 09, 2023 @11:34PM (#35508925)
> In production

Did you know Ruby has a garbage collector not unlike this one? People are running it in production right now.

> a toy GC

It does its job. These algorithms have been working for decades now.

> without threading support

It can just stop the whole world.

> without register scanning

Add some inline assembly to spill all the registers. I did this on my own language implementation not even a month ago. If this was a real project I'd submit a patch.

The author even acknowledged this limitation and hinted at how to solve it, he just didn't want to get into those gritty details in his article. I'm happy to demonstrate if you want.

> Imprecise also. How do you seperate large ints from pointers?

You don't. You collect conservatively. It will have false positives but not false negatives. In other words, it will mistake some ints for pointers but it won't collect memory that's in use. Correct if suboptimal behavior.