5 ms·
How hard is it to build a c compiler with garbage collection and compile all the the pre-existing code with safe garbage collection ?
by foobar_ 7y ago
How hard is it to build a c compiler with garbage collection and compile all the the pre-existing code with safe garbage collection ?
- mynegation 7y agoYou don’t even need a compiler for this. https://en.m.wikipedia.org/wiki/Boehm_garbage_collector https://en.m.wikipedia.org/wiki/Boehm_garbage_collector
- foobar_ 7y agoI know about that one but can I compile mysql, httpd and all its dependencies with it enabled? I don't care if it is 100x slow.
- stormbrew 7y agosure. free() just becomes a noop. But probably they'll leak a bunch because conservative gc is kinda bad, doubly so in code that isn't made for it. (it's really a little more complicated than that in codebases, like mysql, that probably manage their own allocation and actually care about page level stuff)
- felipellrocha 7y agoI think this is asking the wrong question
- chrismorgan 7y agoYour question is utterly off-topic on this thread. But the short answer is that you can’t, it’s fundamentally impossible. Garbage collection still requires that memory access be principled, so that it can determine when something is no longer in use; but things like pointer manipulation in C scupper that.
- adamnemecek 7y agoWhy bother with this?
- twic 7y agoThis is a perfectly reasonable question, asked out of innocent curiosity; the negative reactions to it are disgraceful. I think building such a compiler would impractical, because in C, you can turn a pointer into an integer and back again. While it's an integer, you can hide it in ways that would make it invisible to a garbage collector. For example, in a xor linked list: https://en.m.wikipedia.org/wiki/XOR_linked_list https://en.m.wikipedia.org/wiki/XOR_linked_list