Hacker News new | ask | show | jobs
by messe 1748 days ago
> that will need to bootstrap first, and you won't be able to use such GC code in the initialization code for the OS.

It's all highly dependent on the interface between the language and its runtime. Hypothetically, your C# runtime (and by runtime, I'm using it in the same sense that Rust or C++ would use it; I'm not referring to a VM) could provide a function that allocates memory (C#-esque pseudocode):

    public static ulong New(ulong bytes)
    {
        if (gcInitialized)
        {
            return GcNew(bytes);
        }
        else
        {
            return BootstrapHeapNew(bytes);
        }
    }
Until the GC is boostrapped, all allocations are made on a heap, and either manually freed or kept around until the GC takes over deallocation.

> GC code using Boehm would not be suitable for device drivers nor realtime code.

I completely agree, I just provided it as an example of a GC implemented in the same language.

> Where do you envision the GC bootstrapping and how do you see it interacting with virtual memory and your malloc implementation?

I don't see the GC interacting with userland in this case, and instead would only be used for kernel data structures. I don't really think it's a good idea to have GC in a kernel, I only wanted to point out that low-level code and garbage collection are not mutually exclusive.

1 comments

For that matter, until you bootstrap GC+heap, you could just use statically allocated memory, or even local arrays (via stackalloc). This would preclude using any reference types, but you can do plenty of things with just structs and unmanaged function pointers alone in C# (it's basically the expressive equivalent of C, but with generics thrown in).