Sign in to follow this  
lack o comments

need tip for resource manager

Recommended Posts

I'm writing a new resource manager (you probably gather that from the thread name =). Anyway, I want to include a database that keeps a list of all filenames used in the project. My question is, would it be advisable to keep the list separate from the actual resource data, or combine them and just use state flags to determine which are loaded and which aren't. Thanks in advance.

Share this post


Link to post
Share on other sites
Hi,

My resource manager maintains a map of filename to resource tags for a given resource type:

template<typename resource_type> struct resource_tag;
std::map<std::string, resource_tag<myRes> > resources;

The resource tag contains information such as a reference count for intelligent caching; the tag also contains a pointer to the actual resource class:

template<typename resource_type>
struct resource_tag
{
// various attributes...
unsigned int m_refCount;
resource_type* m_pResource;

// increment reference count
void AcquireResource(const std::string& filename)
{
if(m_refCount++ == 0)
{ m_pResource = new resource_type(filename);
}
}

// decrement reference count
void ReleaseResource()
{
if(!--m_refCount)
{ delete m_pResource;
}
}
};

My resource handles update the reference count on a resource tag, and this triggers the load/release of a given resource.

Hope this helps. :)

Share this post


Link to post
Share on other sites

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