Upcoming Events


Quick Stats
3706 people currently visiting GDNet.
2236 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

  search:   

A Simple Fast Resource Manager using C++ and STL


Structure

The Resource Class

To enable consistent handling and initialization across various types of resources, we have used a common base class for all resources. For fast access, we have chosen to use unsigned integer handles for each resource. The resource class also has a reference count and members to hold the file name and path. The following figure shows the members of the class:

The ResourceManager Class

The ResourceManager class manages different types of resources. We use a different ResourceManager instance for every type of resource, and thus the ResourceManager is a template class. The members are shown in the following diagram:

The ResourceManager class has four member variables. m_list is a pointer to a vector which holds pointers to resources of a specific type. The resources are instances of the Resource class, or a class that derives from the Resource class. The stack m_handles is used to keep track of free slots within the m_list vector. Its role is explained later. The third member, CreateResource, is a pointer to a callback function that is called by the resource manager when a new resource is being added.



How it Works


Contents
  Introduction
  Structure
  How it Works
  Usage

  Source code
  Printable version
  Discuss this article