My question if about resource management. Is it a good idea to store resources like Sounds in an array and then make a second array(lets call this SoundCollections) as a sort of reference table(name + index of sounds array).

The SoundCollection structure looks like this:

struct SoundCollection{
    unsigned char name[64];
    unsigned int offset;
    unsigned int count; 

GameObjects can aqcuire a SoundCollectionHandle and use the SoundCollection[SoundCollectionHandle].offset in the Sounds array. GameObjects then can call

Audio.playsound(Sounds[SoundCollection[SoundCollectionHandle].offset + PlayerSounds::Jump])

for playing a jump sound.

The SoundCollection::count is used as offset for next SoundCollection and bound checking. The same thing I want to use for Sprites and Textures.

Are there any other methods you usually use in your games?


1 Answer 1


There's absolutely no reason to store your sounds into the same array, since you need to devise an elaborate scheme to get them back. Basically you cannot make it smaller, because your sounds take the most space, and indexes make it only bigger. You cannot make things go faster, because additional level of indirection does not make thing go smoother.

You'd be much better off saving every sound into its own file and into its own array and them have them called explicitly by name.

  • \$\begingroup\$ Does this also work for sprite animations? \$\endgroup\$
    – user389006
    May 19, 2014 at 18:17
  • \$\begingroup\$ it depends. basically, sprites could be composed into the same image, say, 128x1280 (for ten 128x128 sprites long vertically), in this case it might be a good idea to save them all together since they have the same colour palette and access them by the offset. not so much with the sounds, because they have no palette or any other quality that requires them all to be saved together. \$\endgroup\$
    – lenik
    May 19, 2014 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .