4 ms·
This is the quickest way to kill your performance in C++. I guarantee it wasn’t what Carmack was talking about. I used sharedptr extensively in a game engine.
by sillysaurusx 7y ago
This is the quickest way to kill your performance in C++. I guarantee it wasn’t what Carmack was talking about.
I used sharedptr extensively in a game engine. Whoops: suddenly 20% of the frame time was gone, never to be recovered. Once that performance is gone it’s almost impossible to get it back, short of rewriting every system.
- deleted 7y ago[deleted]
- naniwaduni 7y agoOn the bright side, you didn't lose 200% of the frame time!
- paulddraper 7y agoYes shared_ptr is relatively expensive; avoid it in your inner loops, but know that it's there for the other 80% of your code.
- wffurr 7y agoOnly use shared_ptr when you actually want shared ownership. If you stick to unique_ptr for owning references and then "borrow" that raw pointer in functions, then you get speed without sacrificing too much safety and still no new/delete.
- slavik81 7y agoAdditionally, shared ownership should be rare. Most objects should have a single owner that is responsible for them. This is not only better for performance, but also makes the system easier to understand.