Live data from Hacker News

Writing a Simple Garbage Collector in C

maplant.com

21–24 of 24 posts

Re: Writing a Simple Garbage Collector in C

#21
This really reminds me of a project called TinyGC/tgc[0], made by Daniel Holden who is currently a Ubisoft researcher. I have also tried his Cello[1] framework for C99 which also incorporated a garbage collector similar to tgc. Cello is pretty fun to use but the syntax was still limiting.

[0]: https://github.com/orangeduck/tgc

[1]: https://github.com/orangeduck/Cello

Re: Writing a Simple Garbage Collector in C

#23
post #9

Earlier quoted context omitted.

> None of this is thread-safe. It needs a global mutex lock. Or have a separate allocation chain for each thread. It would increase fragmentation, but not by a lot, and probably increase performance by more than enough to make up for it.

The problem is that you would still need to lock around sbrk.

Fair enough. You would probably switch to mmap, though, which works across threads.

Re: Writing a Simple Garbage Collector in C

#24
post #4

Earlier quoted context omitted.

Does this picture change much between the 32-bit vs 64-bit world? How about if there are few vs many threads? (For instance, if a program on 32-bit windows spawns hundreds of threads, surely you can't squeeze all those stacks below the heap, can you?)

The 64-bit address space is much bigger and even more unpredictable when there's ASLR, but in my experience the main thread's stack still ends up below the executable; they're just much farther apart. I believe other threads' stacks also fit somewhere below, but with 32-bit it will start allocating them in areas that would've otherwise been heap once the area below the executable runs out.

thanks!
Post reply on HN