Archived

This topic is now archived and is closed to further replies.

managing game resources & memory managers

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

Hi, I''m bored of load the resources of my projects by hand (hardcoding a huge list of loadthis & loadthat) and I was thinking in doing some sort of resource manager that could load a whole set of resources with a single call. as game resources, I mean all general resources that are needed for a project, from 3d models, maps, scripts, text strings, bitmaps, score tables, GUIs, paths... everything. Also, I''m worried about the management of memory... I''ve seen lots of projects arround that call Malloc and New for every single little structure of the game, I don''t like that because it fragments memory too much, and may result in memory leaks. Another method I''ve seen is to request a very big memory block and use it as a memory stack, I think this is a lot more clean, but in real projects, you never know how much memory you''re going to use, and you end up requesting much more memory than needed, and this si bad for systems with not too much memory (pocket pc, consoles...) so, what do you do to to manage game resources? is there a good general approach used by everybody?

Share this post


Link to post
Share on other sites
I would say, that calling new frequenctly is not that bad, as logn as this is done in an initialization stage. Fragmentation of memory happens from reallocating a lot, and a lot of allocation on the fly. If you need to constantly change resources in actual game play (like a dynamic routine to only keep the immediate vicinity loaded etc) then managing the memory yourself can be preferable. If most of your data is preloaded, new/delete is not a prob. I would recommend that you wrap all your resources allocation in templated classes. This applies to opening files, getting device contexts, and anything that has to be obtained, then released. A good scheme is detailed here. I hope this helps

Share this post


Link to post
Share on other sites
I wouldnt worry about getting a big block of memory, that is waht system req are for. You say this game needs 64 megs of free ram and if they dont have it then its there fault for buying that game.

Share this post


Link to post
Share on other sites
About memory managers I recommend using boost:: pool, and if you can you should always try to use smart pointers like boost::smart_ptr

Don't know if I understood the first part right, buth you're qurious about object management? Outside the game engine? Like "these are all my objects, load em up cause I'll be asking for them!"? Ehm, the easiest way might be to make a tool? Where you specify what textures to load and it'll make a load.txt file that your engine can read?

I've had my thought on stuff like that too, especially around scenes. What I think is that in the beginning your resource managers load up all objects that will be used in this scene, and then the scene only reference to them by name.

example file, XML style:
// Load up object manager
< item type="weapon" name="MyBigGun>

< image>biggun.bmp< /image>
< /item>
// etc.

// now for the scene
< house x="200" y="200" width="100" height="100">
< item ref="MyBigGun" posx="20" posy="10" />
< /house >



eh kinda lame example but you get the picture right? There's only one definition for MyBigGun, but several referenses to it. Your object manager is responsible for "loaning" out it, or duplicate it, depending on your need.

}-- Programmer/Gamer/Dreamer --{

[edited by - Seriema on October 10, 2003 10:28:27 PM]

Share this post


Link to post
Share on other sites