Archived

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

monkeyography

memory management

Recommended Posts

I just wrote a resource manager for my game(directx) and I need to know some of the finer details in memory management to get things nice and efficient. Basically, when I want to use a model (animated mesh) or an image I make a request to the resource manager which loads the file or just passes me a copy if it''s already been loaded. Each resource keeps count of how many times it''s being used and I can call a garbage collection function to dump anything that''s not being used. Anyway, I''m not sure whether, between levels, to load all the resources for the new level then call garbage collection, or call garbage collection then load new resources. There may be some resources shared from level to level so if i load before dumping, I could avoid loading those resources again. However, if i load before dumping i could end up having twice as many resources loaded simultaneously, for a tiny bit, and if video memory was exceeded some resources would get stored in system memory. The the delay of loading things to system memory and swapping them back may be a terrible thing; it may also be completely unnoticeable. Is this understanding of memory management more or less correct? What do you think would have faster performance? Thanks

Share this post


Link to post
Share on other sites
quote:
Original post by Vich
How can you call garbage collection in C++?

He''s using explicit reference counting.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Yeah, I just keep count of how many times each resource is used and the garbage collection function I wrote dumps whatever has a count of 0.

I suppose I could just try both techniques and see how they turn out. I wanted to make sure my understanding of "mipmaps and vertex data are stored in video ram until it''s full upon which they''re stored in system ram" was right though so I made a post. (it is, right?) I''ll have to do some testing across different systems to see how it flies with video cards of different sized ram though.

Thanks

Share this post


Link to post
Share on other sites
Post back here with your results, if you don''t mind; I''d encountered the same dilemma, and am interested in which you choose.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
I''m not going to know myself for a month or two. The Resource Manager''s complete but, as I''m the sole artist and programmer, I haven''t had time for any level content yet! Each level is currently represented with a single cube and a single square - not the best test. Eventually they''ll be packed with all kinds of animated crap so I guess I''ll find out then.

Share this post


Link to post
Share on other sites
Could you load in the next level, build a list of resources that it uses, AddRef() any of those resources already in memory, unload the previous level, garbage collect, and then load in any resources you still don''t have?

Just a thought. It would probably require some list of resources at an easy place within the level file.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.

Share this post


Link to post
Share on other sites
Just a quick question about how to manage loaded resources; you say taht you request a file from your RM and if you have already loaded it you get a _copy_ of it. Isn''t that a waste of memory to pass a copy of the mesh or whatever? How would one do otherwise? YOu can''t just pass a pointer, in that case you would eventually modify the resource directly from within the manager!?

I''m just not quite sure how to deal with the files after loading them in this case..

Share this post


Link to post
Share on other sites
quote:
Original post by monkeyography
I''m not going to know myself for a month or two. The Resource Manager''s complete but, as I''m the sole artist and programmer, I haven''t had time for any level content yet! Each level is currently represented with a single cube and a single square - not the best test. Eventually they''ll be packed with all kinds of animated crap so I guess I''ll find out then.

Heh, I know the feeling. So far, I''ve been testing my resource manager with string data of varying lengths; but, of course, this isn''t really suitable for thoroughly testing the loading dynamics.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
quote:
Original post by Deadman55
you say taht you request a file from your RM and if you have already loaded it you get a _copy_ of it.



I meant a copy of a... a pointer. a pointer copy.
yeah, i just pass a pointer to it, bad english error.

quote:
i]Original post by Superpig
Could you load in the next level, build a list of resources that it uses, AddRef() any of those resources already in memory, unload the previous level, garbage collect, and then load in any resources you still don''t have?

Just a thought. It would probably require some list of resources at an easy place within the level file.



things are kind of crazy the way I plan on getting them to work (letting .x files attach other .x files to themselves by naming one of their frames ATTACH_XFILENAME) so I''m pretty scared of making anything more complicated. Good idea though.


Share this post


Link to post
Share on other sites