Jump to content
  • Advertisement
Sign in to follow this  
beebs1

Resource Cache

This topic is 4077 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!