I am lazy. I put things on the stack or use std::shared_ptr for *everything* else. I rather waste some resources than leak anything. But be careful using smart pointers as parameters. In most cases a reference or raw pointer is all you need! #Ownership
During development in some places it will become very obvious where a unique_ptr or weak_ptr is the better choice. Then you refactor accordingly! #Refactoring #C++ #make_shared
@TonyAlbrecht You don't give that up with smart pointers but when the memory is free'd/deleted.
But I understand your sentiment. I also like to be in control but more than that I am lazy 🐵
@aggsol @TonyAlbrecht I've gone back to simple pool-index handles with some extra bits for dangling-handle-detection, and not hand out pointers as 'owner' at all, if direct access from outside is needed, provide a lookup function for handle-to-pointer, but don't store that pointer anywhere
@floooh Sounds interesting. Do you have the extra bits on the handle or do you store them next to the actual pointer?
@aggsol everything cramped into a single 32-bit or 64-bit integer, as many lower bits as necessary for max pool size, higher bits for some unique handle (e.g. counter that's bumped per created handle), sometimes also a few bits for handle type (e.g. texture vs buffer...), also see here (search for Lifetime Management): http://floooh.github.io/2017/07/01/oryol-system-design.html
@floooh Thank you for sharing! I currently have a look at it. It at least makes a great coding exercise.
@TonyAlbrecht @aggsol I use shared_ptr's sparingly, but I do use them. For longer lived objects that you want to share between a few threads they are invaluable.
@sheredom Maybe I'm old school. I want to know exactly when my data is being shared - where the choke points are. I dislike implicit thready safety
@TonyAlbrecht if it was only I maintaining this code, yup I'd agree with you. But I've been bitten too many times by juniors that I'll take the hit and use shared_ptr's :/
@aggsol I never choose to use smart pointers. I prefer to know exactly when and where my memory is allocated. #OldSchoolCoding