I know this question had probably been asked a few times and I did search the forums but couldn't find what I'm after.
My question concerns memory allocation (of resources in a game) and how to avoid having to manage them manually.
At first, my little game framework had (almost) everything wrapped in std::shared_ptr. I think this has impacted performance (AFAIR I did profile it) and also leads to bad design. Recently I removed every use of std::shared_ptr in favor of raw pointers and started to actually think about ownership of memory to define who has the responsibility to free the resources. I have a class called ResourcePool which given a type of a resource, it allocated it and is the owner of the resource and therefore responsible to free its memory. But what if for instance, I would like to clone a resource (because I'm going to change it and don't want everything which uses this resource to be affected). The cloned resource wasn't created using the ResourcePool (The resource pool can create resource only from files) and therefore won't be freed by it which leaves the responsibility to the user. I can think of three solutions to the problem:
1. Use shared_ptr (or probably my own intrusive reference counting) but that's what I was try to avoid in the first place.
2. Leave it to the user, but in the long run is cumbersome and would cause memory leaks if not carefully taken care of
3. Add the resource to the ResourcePool (or other class) which will become the owner of the resource and therefore will free it.
I hope I was clear enough and would like to hear what other designs have you guys used to avoid having to manually manage memory in your game