Something that I have dealt with on and off for the entire time I've been game programming is the idea that I need certain resources to be loaded from file exactly once, but used by multiple entities. I've written several generations of allocator-type classes and structures to manage this, but my latest effort is pretty nifty, fairly safe, and easy. In this iteration, I created a templated class that maintains an std::map of string->object mappings, where each object in the map is a boost::weak_ptr to an allocated resource. Entities that require a certain named resource call the allocator to get a boost::shared_ptr to the resource. In this way, I have a central mapping of name->object that does not itself maintain a shared_ptr; thus, when all entities release a resource, it gets dumped. Although an entry remains in the allocator map, the behavior of weak_ptr is such that it will indicate its expired status, and subsequent requests for the same pathed resource will result in a reload. Having this central mapping also makes it easier to perform iterative operations on the loaded resources, such as dumping, reloading, re-submitting vertex buffers, or what have you, as necessary. Here's my first try at the allocator class. Thoughts?
I perform resource construction via a const char * because many types of resource allocation calls may end up bound to Lua, and this simplifies things.