Appreciate the post, SpeCter.
Most STL implementations are not very resource friendly and their memory allocation might not be a good fit for what you do.
Don't custom memory allocators get you around this problem?
I'm not saying you shouldn't use STL containers , to be honest I like them.
I'm also not saying you shouldn't use raw pointers(or that it's wrong), what I'm saying is that you make your life unnecessarily hard if you don't use the tools laid out before you.
That's a good argument.
There is no technical reason not to use unique_ptr.
As we discussed earlier, a technical case can be made for not using shared_ptr. But I agree with you on unique_ptr. I confess it didn't really occur to me to use the one (unique), but not the other (shared).
That would give you no problems, performance wise. Stylistically though, it might. Now you've got a mixture of some pointers which are managed for you (unique_ptr), and some which are not (raw, for anything not suited to a unique_ptr).
Actually, while I've got a forum filled with smart pointer folks, let me ask a question:
Let's say you've got some class like this:
// "skills" as in RPG-style skills, perhaps combat moves, or other abilities like crafting.
class SkillDirectory
{
public:
// ... constructors, etc...
const Skill* LookupSkill(const std::string& i_skillName) const;
private:
// maps a skill name to a skill class.
std::map<std::string, Skill*> m_mapSkill;
};
The SkillDirectory owns the Skill* memory. However, it serves out pointers to this memory to other gamesystem code that uses it. The list of available skills in the game will never change at runtime. So it is possible for other classes to safely store a pointer to one for the duration of the game.
So let's say that other classes in the game (perhaps some Entity component relating to known skills) will also want to hold Skill* pointers, rather than skill names or IDs which force a lookup every time you need to access the skill. Maybe this is done for convenience or performance reasons.
Is there any way to avoid getting around the use of shared_ptr in this scenario? (Provided you don't want to use raw pointers).