Windows Memory Usage & Games

Started by
15 comments, last by Kitt3n 18 years, 7 months ago
Modern operating systems* cache all your disk accesses in memory. when you read your data from disk into memory, the operating system keeps a copy of the data in memory in case it's accessed again. There's nothing you can do to free that memory, and you wouldn't want to. Next time you try to read that data from the disk, the OS just pulls it out of memory and your start up is 1,000,000 times faster. If you request more memory than is available in physical memory, the OS will release some of its cached data and give it to you. bottom line is don't use task manager to monitor memory usage.

Case in point. Open up a web browser just after your system is fully booted up. You'll hear lots of hard drive clicking. Then close the web browser and open it again. You'll notice very little disk activity.


While I'm talking about memory management, you also should know that there's a difference between physical and virtual memory. When you allocate 1 gig of memory, You are given virtual memory, but the amount of physical memory available to the system doesn't change. It's not until you access the memory that the OS allocates physical memory for you, and this is done a page at a time*.

to get a true feeling of how your user level application is managing memory, you need a tool that will differentiate between memory currently being used by user-space programs and system memory, as well as distinguish between virtual memory and physical memory. I'll defer to windows people to tell you what tools are currently on the market.


[edit] of course, in this case it looks like there was a user-space error.


* I only know for sure how linux handles memory management. I only project that windows would use similar techniques.
Advertisement
kdogg,

Thank you for the long post on memory-- I actually knew most of that (paging, thrasing, how main memory vs. virtual memory and hard-drive memory works, etc.)... but some of it I didn't. I guess I just never realized how "freeing" resources worked... I thought as soon as I called delete on dynamic memory, I got it back instantly.

Thanks for the heads up on this... I'll have to be more careful in the future.

-dbh
------------------------------------------------------------GDC/IGF 2006 Student Showcase Submission: Curator Defense
Good to hear you got this resolved dbh.

kdogg brings up a very good point, but I would not expect the memory that is being used by the OS for IO caching to show up on your memory profiles.

There are multiple ways to do memory profiling, and there are tools out there that could help you.

In your case I believe that using the debug runtime for DirectX and setting the output level to the max would have given you information about the leak on application exit with the debugger attached.

If I remember correctly WIN32 has functions for getting information about the memory used in your process. There are also C-runtime functions that would help you track memory leaks down (Look for _CrtSetXXXX in MSDN)

Some commercial tools like BoundsChecker could help you as well, but such tools are expensive and target a production setting. You can download the trial version to try it out.
AH yeah, Bounds Checker is nice... I remember trying that awhile back. I also LOVED the Purify Plus license we had at DigiPen. So powerful!

But alas, us poor, independent programmers can't afford such fineries. I'll take a look into that. Thanks again!

-dbh
------------------------------------------------------------GDC/IGF 2006 Student Showcase Submission: Curator Defense
Kinda curious myself, what would be a better way to check how much memory your application is using instead of ctrl-alt-del window?
If you're using C++, you could override the global new and delete operators with versions that track memory usage and an interface to query it. I did something similar a while back with the purpose of tracking memory leaks. Enabled it only for debug builds, so they were a little slower when lots of dynamic allocation was going on, but release builds ran at full speed. This would only track the memory allocated in your program however, not things you've got in video card memory.

Edit:

For languages that don't allow overriding the allocation functions, you could just create wrappers around them that do the tracking.
---"While there is a lower class I am in it; while there is a criminal element I am of it; while there is a soul in prison, I am not free" - Eugene V. Debs---
Also take a look at "Paul Nettle's Memory Manager" or take a look
at the one in ogre (derived from Pauls).

They help track down leaks and at least the one in Ogre has some
runtime usage info (and heck, you can even but breakpoints on the
x-th allocation!)

/R
visit my website at www.kalmiya.com

This topic is closed to new replies.

Advertisement