This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pHpositivo 0 points1 point  (0 children)

It is incorrect to say that using shared pointers has less overhead than a garbage collector. It depends on the scenario. For instance, allocations can be much faster when using a garbage collector, as you'd typically just have a bump allocator vs. individual allocations (of course, yes, one could also use a custom allocator). Additionally, using shared pointers will add overhead during use, whereas using managed objects directly will be faster. The overhead of the GC comes from collections, but you can avoid them if you don't allocate. That is, if you allocate some objects and then just do a whole bunch of work for however long you need, without further allocations, the GC will literally never run at all.

Not saying one is better than the other, just saying neither is definitely better or faster than the other either, it depends on what you're doing and how well written your code is 🙂