memory management

Started by
9 comments, last by monkeyography 20 years, 11 months ago
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
Advertisement
Sounds like it will be a trivial change to make, so why not try both and time them?
How can you call garbage collection in C++?
[www.LifeIsDigital.net - My open source projects and articles.
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.
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
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.
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.
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.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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..

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.

This topic is closed to new replies.

Advertisement