Data handling

Hey guys,

I need a little advice from you. Right now, my graphic engine projects loads a model from hdd (let’s say, a cube) and copies this cube for every object in the graphic memory (so, if i load 300 objects, i have the same model 300 times in my memory), which is, politly said, a waste of memory.

I’m planning to load every model only once into the memory, the same with textures and so on. Now I started a discussion with a friend, if it is better to hold every model/texture once in the memory or to unload it when it’s unused for a certain time.

What do you think which way is better? I think it’s better to hold the data, so I don’t have to reload it, when it was unused for a while.

I hope you can help me (as well as I hope, that I’m in the right subforum)

Have a nice day,

Unless you have to handle a big number of different heavy models, you can stick with loading it once in memory for ever.

Then, a more appropriate approach can be some sort of cache :

  • keep a list of active objects : A
  • a list of loaded objects : B (all A is included in B)
    This B list contain for each model, its size in memory and the last time it was used.
    When total of (memory taken by B - memory taken by A) is too big (you can have a configurable threshold, or use other metrics such as total memory taken by your app, etc), deallocate the least recently used models.
  • then when the A list need a model which is not in B, load it from disk.