std::vector (or queue, or list) or Chained pointers?

Started by
0 comments, last by ToohrVyk 16 years, 11 months ago
I'm working on a graphics system that handles resources like textures, and eventually even game objects by using a list/stack/chain of resources that are created and added to the stack, then randomly acessed out of it by the system. I need a fast storage system for these resources. Should I use an STD container (such as list or vector)? Or will a group of resource classes chained together with poitners be faster (or use less memory) here is the class that I am thinking about (I don't have my index function written yet)

class iResource
{
protected:
// this is a base class designed to be overloaded depending on the specific      // resource to be acessed. I am considering using void pointers instead, it 
short index;
iResource *next;
iResource *prev;

public:
iResource();
iResource(iResource &rhs);
~iResource();

void Delete(); //close the gap created by deleting this index
};

I expect to add some basic functionallity to this class later, but right now I am going for absolute basics. Anyway, I know that this does not have the power of the STD classes, but I am tring to make it lighter than they are. Am I better off just using the std library?
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be
Advertisement
As it stands now, your system uses more memory than an std::vector and std::list implementations, and possibly also std::deque. It's also slower than std::vector and std::deque, and possibly also std::list depending on your usage and your implementation.

Remember: nobody can outperform the standard library containers without determining their weaknesses first, which means that you should write the initial code using the SC++L anyway, and only then determine if, and how, you can try to increase performance or reduce size. For a resource manager, I'd say the effort is not worth it anyway.

However, the biggest problem is that your class violates the Single Responsibility Principle (because it's both a resource and a linked list node). Even if you don't use the SC++L for storage, at least separate the two responsibilities (storage versus function).

This topic is closed to new replies.

Advertisement