Sign in to follow this  
md_lasalle

Loading map data in a Thread

Recommended Posts

md_lasalle    190
Hi all! I'm a bit new to threading and I was experimenting with loading a game map in a thread, because by doing so, i can still communicate via my network layer to players trying to join the game while i'm loading. So basically it goes like this : - Main thread starts the map loading thread - When loading thread finishes, I upload vertex and texture data to vram - When map is finished, the main thread deletes all resources that the map loading thread created. Now my problem is I can see a good 1.5 mb ram increase after each map load. I've tried running VLD memory leak checker, but it didn't find any leak in my map load/unload process. I'm wondering if the fact that my resources are getting unloaded by a different thread than the one who loaded them could be the problem. Thanks for any light on this.

Share this post


Link to post
Share on other sites
streamer    415
Well, this is too few info to get on it. But you can get memory leaks undetectable by any other means. I had lot of memory leaks in my last project, which visual studio didn't reported at all. Just after program crashed I recognized that something is wrong.
Debugging through code line by line showed where the errors where.

I'm not sure, but it is possible that different thread freeing resources from main thread can be the problem. For example lot of problems can be found if you are using COM objects from another thread that loaded it.

To find what is happening with your resources, debug your program line by line (in loading thread) and check for the point where your program is eating resources. So when you step over one function and your program grows by another mega and a half you will know where and what to search.

Share this post


Link to post
Share on other sites
Evil Steve    2017
I hope you're not using Task Manager to judge your memory usage. Because that bears almost no relation to the memory allocated by your process.

How are you detecting this memory leak?

Share this post


Link to post
Share on other sites
md_lasalle    190
Quote:
Original post by Evil Steve
I hope you're not using Task Manager to judge your memory usage. Because that bears almost no relation to the memory allocated by your process.

How are you detecting this memory leak?


Well it's not that I'm "using" the task manager to detect a leak, it's just that after leaving my server/client running for like 40 maps (always using the same map) it never stops going up by 1 mb per map switch. If when I initially load the map, the game uses 230 mb ram, why would it need 700 mb ram a few hours later ?

Any suggestions Steve ?

Share this post


Link to post
Share on other sites
md_lasalle    190
Quote:
Original post by neonic
Probably because you are allocating memory and neglecting to free it when the time comes.


Yep, I know that's probably the case, but since I don't have much experience with Threads, I just wanted to clear this out before starting to investigate the map loading (the thing is quite big).

Share this post


Link to post
Share on other sites
Adam_42    3629
Have you tried using the D3D debug runtimes? Leaks of D3D resources won't show up in VLD, but the debug runtime will pick them up.

I'd also suggest having your main thread do both the creation and deletion of the vertex and index buffers, that way you won't need to use D3DCREATE_MULTITHREADED which slows things down significantly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this