Upcoming Events
Tokyo Game Show
10/9 - 10/12 @ Tokyo, Japan

IndieCade
10/10 - 10/17 @ Bellevue, WA

Blizzcon
10/10 - 10/11 @ Anaheim, CA

2nd European Conference on Games Based Learning
10/16 - 10/17 @ Barcelona, Spain

More events...


Quick Stats
3708 people currently visiting GDNet.
2222 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



Contents
  Introduction
  Structure
  How it Works
  Usage

  Source code
  Printable version
  Discuss this article

Introduction

Resource management is a vital aspect of game development. Every game has resources of various types and an efficient resource management system can improve the overall performance of a game. In this article, we look at an implementation of a resource manager that can be set up with minimal effort, yet which provides noticeably better performance than more generic approaches.

The Role of a Resource Manager

A resource manager manages various resources of a game. Meshes, sounds, scripts, shaders, textures can all be considered as resources, yet they have one thing in common: they are loaded from files before use. A resource manager can handle the mundane tasks associated with loading and accessing the resources. Ideally, the resource manager should be fast, efficient, should use minimum memory and also be easy to use at the same time.

Design Goals

Our resource manager should satisfy the following goals:

  1. It should be consistent across various resource types.
  2. Access to resources should be done in O(1) time.
  3. Insertion should reuse previously loaded resources.
  4. Insertion should reuse slots for resource pointers that have been free up due to removal of resources before making new slots.
  5. Removing a resource should be at most O(1).
  6. Using it should be simple.

Approach

To achieve the goals above, we are using the following:

  1. C++ templates to enable use for all resource types.
  2. A simple base resource class so that initialization of some parameters is consistent.
  3. Reference counting so that the same resource is not loaded off disk multiple times.
  4. STL to simplify basic coding tasks.




Structure