Resource Management 0
There have been some posts recently to GD-Algorithms concerning resource management. This happens to be an area I’ve investigated recently as part of my Sandbox project (which, btw, is becoming more of an excuse to experiment with different design patterns than actually doing game-code at the moment).
I’m going to define a resource manager as needing to have the following qualities:
- Provide universal access to all modules needing to retrieve externally persisted data (resources).
- Ensure that resources exists as a single, shared instance in memory.
- Ensure that resources are properly garbage-collected as necessary.
- Allow resources to be retrieved/referenced by unique key.
These requirements immediately evoke several classic design patterns that we should be leveraging. First, the universal access requirement means that the resource manager should be a singleton. Second, the two requirements of shared instance and garbage-collected means smart pointers. Finally, retrieving by unique key smells of some variation on the factory method.