Sign in to follow this  

Resource Cache

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya, I'm having a bit of trouble implementing the template resource cache (manager/pool) for my current project, and I was wondering if anyone could give any suggestions or pointers (haha). The cache dynamically loads/unloads resources from an archive file to stay within a given memory budget, which is causing a problem: Calling Type *ResCache->Get( const char *pName ) simply loads the requested resource if it was not already loaded, and then returns it. It might unload other resources in order to stay within it's memory budget. The problem is that a resource may be unloaded to make room for another, and then need to be used again in the same frame. The only way I can think of getting around it is every time a resource is used, I call Get() again to make sure it is loaded, which seems like a lot of overhead for something like drawing a mesh 50x, 100x or more per frame... The resource interface class, from which all the resources inherit, has the Load() method, but I call this only from inside the resource cache as a load of management homework has to be done at the same time. Or perhaps I could have IResource::Load() call an Update() method in the rescache to do this homework? I hope that was clear enough, any input would be very much appreciated. The general idea is to make the dynamic loading/unloading transparent to the client using the ResCache class. Thanks for any replies [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by beebs1
Calling Type *ResCache->Get( const char *pName ) simply loads the requested resource if it was not already loaded, and then returns it. It might unload other resources in order to stay within it's memory budget. The problem is that a resource may be unloaded to make room for another, and then need to be used again in the same frame.

The only way I can think of getting around it is every time a resource is used, I call Get() again to make sure it is loaded, which seems like a lot of overhead for something like drawing a mesh 50x, 100x or more per frame...


This is the characteristic behavior of a cache. The key is to maintain coherency. That is, try to ensure that objects used frequently remain in the cache.

The most common type of cache is an LRU cache (least recently used). In this type of cache, the oldest item in the cache is discarded first.

Surprisingly, the MRU (most recently used) cache is not uncommon. Look here for other strategies.

Share this post


Link to post
Share on other sites

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this