SGCL: Real-time garbage collector for C++
github.com
github.com
I'm not saying that it's a bad idea. I'm just curious about why/when garbage collection is better than conventional use of unique_ptr or shared_ptr.
When one wants the flexibility of C++ with the productivity of a GC.
So far my experience has been that (nondeterministic) GC is only a productivity improvement over languages with manual memory management like C, but a productivity degradation over languages with deterministic automatic memory management like C++ and Rust. GC manages only memory, while in the latter case, you get automatic management of resources of any type, which can be a huge productivity boost if you use it to your advantage.
Also RAII is great and all, yet there lots of ways to get it wrong.
Badly implemented destructors, missing virtual destructors in hierachys, throwing exceptions on destructurs, not using handle types on heap allocated data, incorrect pairing of allocators.
> Badly implemented destructors, missing virtual destructors in hierachys, throwing exceptions on destructurs, not using handle types on heap allocated data, incorrect pairing of allocators.
Those seem to be more specific problems with C++ rather than RAII. Rust has none of those.
Having a GC is an option alongside the other ones, an option that both Epic and Microsoft think it is worth enough money to spend development resources on.
And Google as well, actually, as Chrome uses a C++ GC, seen as way to fix security issues, Olipan.
Every language with a GC is distinct, and should be properly analysed instead of putting all into the same box.
The adoption of a particular memory allocation strategy depends on a lot factors. This is C++ after all.
Firstly, that's orthogonal to my original point is that, for example, a semi-space nursery can significantly reduce the cost of short-lived allocations (often being faster than malloc/free on such a workload), but only if there are no destructors.
Secondly, threads typically share resources so running something on a different thread does not magically cause it to not disturb the mutator. Such a claim makes me start to doubt the "real-time" claim in the title...
[1] Multithreaded Python without the GIL https://docs.google.com/document/d/18CXhDb1ygxg-YXNBJNzfzZsD... [2] Low-Latency, High-Throughput Garbage Collection https://users.cecs.anu.edu.au/~steveb/pubs/papers/lxr-pldi-2...
tracked_ptr: 279.95ms (151MB)
shared_ptr: 1035.07ms (480MB)
source: https://godbolt.org/z/jP7ohPehY
not sure about others, but i am using emacs with various tools f.e. for c++ these days, clangd as lsp-server, for c (long time ago) it was mostly cscope (via xcscope.el iirc) etc. etc.
Edit: Although 2k lines in file does not quite qualify as large in a lot of the projects. (Not that I like it, I prefer to break them up)
In regards for how to grok and grep code like that, it’s just a skill like any other. I got very good at reading code and forming a mental model of it.
And that's just the main file, it uses several libraries for lower level operations.