Say I have a list of N objects. Each object has, say, an image (could also be files, or even another code object). Every object does not have a unique image, so to save memory consumption, a cache class of the sort would be convenient. This image does not need to be modified in any way at run time. Being able to allocate and delete these resources (when it is no longer being used by any object) at run time would be nice.
Of course I could do something like creating a class wrapper around a map object and handle the creation and deletion of resources through that. However, unless the other objects check the wrapper class if the resource exists, that could cause problems.
I could then of course create a map of ints and maps, where the ints represent the amount of objects associated with that resource, and use it from there, which would work fine.
However, I'm more interested in knowing if there are there any developed design patterns/classes (doesn't need to be a specific language) designed to handle such a situation? Any input on the concept in general would be good too.
This post has been edited by Mylo: 10 May 2013 - 05:01 AM