Skip to main content
gamedev.net
🔒 Locked

Data Pools

Started by normal31337guy Jan 9, 2005 at 10:51 AM 0 replies 1k views
Original Post
normal31337guy
normal31337guy
I am trying to implement some data pools for materials and textures and I was wondering how I should do it. Should I dynamically create an array of size, say 50, and as soon as it is entirely filled use memrealloc to make it larger, and then as soon as it is filled, resize it again. Or should I use vectors to dynamically allocate memory. Or should I use vectors to contain a group class which creates the required arrays. I've seen different books use different techniques. The first and second one are the easiest to implement, however I'd like to know which is faster or better in any other way. Or is there another way I should be looking at this problem perhaps?
hplus0603
hplus0603
Realloc is annoying, because someone who has a pointer to the actual element would have that pointer invalidated; thus you have to pass indices around rather than pointers to elements. If you don't have to scan through all the items all the time, something like a list would probably work better.

However, it's un-clear what the storage is really for. Is it a map from path name (lowercased) to actual resource? If so, a hash table will be more suitable.

And, last, I would recommend using one of the standard library containers, rather than writing your own. Life is too short to spend time re-inventing the wheel, unless you have a really good reason to.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.