Advertisement

Total Memory Used

Started by March 04, 2000 08:14 PM
5 comments, last by Omalacon 24 years, 9 months ago
Just wondering... is there an ANSI or Win32 api function that can tell me how much total memory is being used by my app. Thanks. -Omalacon
Well, there isn''t any ANSI function I''ve ever heard of to get the total memory used by an app, but you can use the sizeof(x) function on pretty much any data type to obtain it''s size. Obviously, the summation of all the data is the minimum size of an app. There will be some additional memory used for the actual code/system resources. Remember that dynamic memory is rather hard to measure.

I have been running some memory tests on a game I''m developing, and I might offer that unless you''re coding really sloppy, you probably don''t have to worry about it too much. Remember that an Int is 32 bits, and there are 2^20 bits per megabyte. If you do the math, thats 32768 Ints to fill a meg of memory. Unless you have built some pretty big arrays, you''ll probably not run into memory issues on computers these days.

Hope that helps.

Rog
R.HillTigger@Bung.Org"Wasting Bandwidth since 1980"
Advertisement
When you look up System Information in Windows, it says something like "System Resources: 83% free", that means 83% of your available RAM is unused. So if it says "94% free" before you start your game, and "44% free" while your game is running, and you have 64 mb of RAM, then your game uses 32mb. Of course, this is an inaccurate way of doing it, since at one time your game may have used more memory, which was later dynamically freed.

The only perfectly accurate method to determine RAM usage is to test your game on various computers, with 8mb RAM, 16 mb RAM, etc. If it runs in 16mb but not in 8mb, then it basically requires a computer with 16 MB of RAM.

~CGameProgrammer( );

~CGameProgrammer( ); Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Well, I use Watcom more than VC, and it has functions to return the total amount of memory you''ve allocated by walking the heap. I have to imagine that VC has some equivalent. Its pretty nice, since I can (and do) calculate how much memory I''ve used, and check how much is allocated at the end to make sure everything is being freed, down to each byte (yeah, I''m a freak).

Correct me if I''m wrong, but doesn''t the system resources refer to more than just memory? And just as a sidenote, the % free refers to free memory besides what Windows is using. Win3.1 had it including itself, but Win95 doesn''t, so it makes it look like their are more free resources when running 95. It''s a big scam.

Rock
Rock: I was just making an assumption about the System Resources thing. I assumed it measured only RAM. And I didn''t know about the ''walking the heap'' feature. How does that work? Do you have to Alt+Tab while your application is running, and run the command to find out how much memory the program is using?

~CGameProgrammer( );

~CGameProgrammer( ); Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
If I remember system resources represent windows resources (like windows handles, and gdi resources) not RAM. Not sure about this, but I am pretty certain. Or are you talking about using system monitor, or resource meter? You think MS could come up with names for resources that were a little clearer.

-Omalacon
Advertisement
I just always thought the resources refered to everything (handles, Ram, files, .....). But that was my impression, I could easily be wrong there.

As for walking the heap, it isn''t a tool, but something you call from your program. Look up _heapwalk in the help (it isn''t ANSI, but it appears to be in both Watcom and VC5). I use it by making a function called Report(char *), which does a for loop to calculate the amount of mem used (the VC Help has the basic loop logic), and then just logs it to a file with the string tag I pass in. Generally I call it at program start, and at the very end, and although they won''t match (there are small things to consider like file buffers used, and buffers for things like printf/fprintf which I use, but I won''t go into that. Just realize that they also affect the total mem allocated result, and they aren''t freed by you), you can nail down what the difference should be between start and end amounts. And you can also call it anywhere, to check how much memory you''ve allocated after you''ve loaded an entire level, for example.

It doesn''t take into consideration code and stack sizes though. Just the dynamic heap.

Rock

This topic is closed to new replies.

Advertisement