Sign in to follow this  

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

This topic is 3859 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

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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

This topic is 3859 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.

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