Trying to reduce memory

Started by
2 comments, last by neatdev 16 years, 6 months ago
I'm working on my hobby, making a small game engine. And together a small game where you just walk around... Most of the stuff is working, I am doing some things to speed it up and reduce memory used. I have used the NeHe tutorial as base to create a window. I work on Windows XP and use the Win32 commands to create a window. The problem I am having is when I start my game (windowed or fullscreen) and do all initializing stuff the game is allocating 87 MB of RAM. But if I minimize the game window it drops down to 1.2 MB!! When restoring the window to its initial state the memory goes up to 5 MB. I really do not know what is going on here. Do any of you have any idea what could be causing the great difference in memory just by minimizing/maximizing the window? I load up a lot of textures, bind them and then delete the texture data memory. I am not doing any fancy stuff when minimizing the window. Just use an ordinary callback function to listen to window messages. The code below shows what happens when a WM_SIZE message arrives:

case WM_SIZE:
		{
			switch (wParam)
			{
        // Was window minimized?
				case SIZE_MINIMIZED:
				{
					window->_visible = false;
					break;
				}

        // Was window maximized?
				case SIZE_MAXIMIZED:
				{
					window->_visible = true;
					break;
				}

        // Was window restored?
				case SIZE_RESTORED:
				{
					window->_visible = true;
					break;
				}
			}
			break;
		}

Advertisement
What you see in the task manager under the "Mem Usage" column is the working set. That is, the memory currently allocated IN THE RAM. Note that this value can be higher than what your application actually uses (because windows decided to give more "in case of"). But it can also be lower than what your application actually using! That is the case when a chunk of the application's memory has been removed from the RAM and put in the pagefile.

What happens when you minimize an application is that windows will automatically trim the application. It means that windows will put the memory which isn't currently used from the RAM to the pagefile. It looks like some memory has been freed but it hasn't! As soon as the application will need to access the memory 'removed' it will automatically be put back into the RAM.

In the task manager you can add a column named 'VM Size'. That column lists the total memory allocated by the application. You can add that column via the "View > Select Columns" menu. Note that when you minimise an application the VM Size doesn't actually change.

If you want more information about memory mecanisms you should read this : http://www-128.ibm.com/developerworks/library/j-memusage/
If you are really interested in seeing what is consuming the memory you can use the tools provided by Microsoft (debugging tools for windows). This will allow you to inspect the memory and/or dump it to analyze later.

http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx

Cale
Thank you very much for that explanation!

Well, then maybe I do not need to focus on reducing allocated memory from an already low level of 5 MB!

This topic is closed to new replies.

Advertisement