2 ms·
> There is a small computational cost to maintaining referenced pointers but it’s minuscule and the safety outweighs this cost. Atomic reference counting does
by pcwalton 11y ago
> There is a small computational cost to maintaining referenced pointers but it’s minuscule and the safety outweighs this cost.
Atomic reference counting does not have minuscule costs. See, for example, http://www.hboehm.info/gc/nonmoving/html/slide_11.html http://www.hboehm.info/gc/nonmoving/html/slide_11.html
In particular, note that if you use shared_ptr everywhere you will be end up with much slower code than you would have if you had a good GC. In other words, you end up slower than Java, with less safety and more verbosity.
Browser engines have used custom non-thread-safe reference counted pointers where possible extensively for this reason.
Furthermore, I always have to say it: shared_ptr is not memory safe.