5 ms·
Ref counting is more efficient than any GC allocator, which is generally the default in C++.
by habibur 5y ago
Ref counting is more efficient than any GC allocator, which is generally the default in C++.
- qalmakka 5y agoI don't know, is it though? Properly done reference counting AFAIK requires using atomic increase/decrease in order to be safe, and that creates a bit of overhead every time you assign a reference, while assignment to a reference with a precise GC is basically a pointer assignment. It's much better for latency though, given that the overhead from rc is deterministic. It has been a few years though since I've looked into garbage collection techniques, so I could be a bit rusty about the current state of the art.
- paavohtl 5y agoYou only need atomic reference counting if you're sharing objects between multiple threads, but if you use an object from one thread at a time then non-atomic inc/dec is enough. Rust allows you to make the choice between the two kinds and the compiler can infer which kind you need to use.
- qalmakka 5y agoYeah - Rust can, because it also ensures you can't exchange data unsafely between threads, but C++ can't. That's why `std::shared_ptr` has to be thread-safe.
- deleted 5y ago[deleted]
- gher-shyu3i 5y agoNot necessarily. Bump allocations are extremely cheap, and collections can be batched to avoid interruption and performance impact.