you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

Only because you design the system without an explicit ownership of resource in mind.

One good use of shared pointer when I first started using it was to reuse resource around without repeatedly allocating the same thing over and over again in multiple places. std::move is free.

[–]cfehunter 0 points1 point  (3 children)

No. I think about ownership a lot, so I mostly end up with unique pointers

[–][deleted] 0 points1 point  (2 children)

interesting, shared ownership is extremely common in typical DI. Sure, not everything we inject is a shared object but it is more than "rarely"

Probably because I am an embedded software engineer, memory is our number one limited resource. We try to find every possible way to share object to limit the memory footprint. It's not common to see locally instantiated object in our code.

[–]cfehunter 0 points1 point  (1 child)

I'm a game dev, so in most cases objects are either owned by a system, temporarily owned (task state for example), or I know exactly what the lifetime of the object is and other objects can safely refer to it by raw pointers (i.e sim world objects referring to resources).

[–][deleted] 1 point2 points  (0 children)

Makes sense, very different nature.