Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Want to determine how much total memory my code uses?

Posted on 2003-11-18
12
Medium Priority
?
311 Views
Last Modified: 2010-04-02
Hello there experts
(you guys are great!)

I want to automate a way to determine how much total memory my program uses up?

I'm using windows 2000 right now, programming with C++ and the Visualization ToolKit library  (VTK)

Is there a way to automate this..? Not sure how to go about this?  
=s
thanks for any input!!


0
Comment
Question by:lost_bits1110
  • 6
  • 6
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9771991
Call 'GlobalMemoryStatus()' and evaluate the 'dwTotalVirtual' member of the MEMORYSTATUS member:

dwTotalVirtual
Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process.

e.g.

MEMORYSTATUS ms;

GlobalMemoryStatus ( &ms);

DWORD dwMemUsage = ms.dwTotalVirtual;
0
 

Author Comment

by:lost_bits1110
ID: 9772971
Thats great..! Thanks for the response..
But I dont know what you mean by "user mode portion of the virtual address space of the calling process"..?

Lets say I have the following program:

int main()
{
-------something
-------something
cout<<ms.dwTotalVirtual;
-------something
}

so does this output the number of bytes used upto that point..??
(Sorry for the dumbness of this question.. =S)
Really appreciate your help,
thanks
0
 
LVL 86

Expert Comment

by:jkr
ID: 9772995
>>so does this output the number of bytes used upto that point..??

Short answer: This is the memory footprint of your program.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:lost_bits1110
ID: 9773026
Okay - so basically no matter where I get the value  of 'ms.dwTotalVirtual', it will return the total memory usage of just the code I'm running in bytes?
0
 
LVL 86

Expert Comment

by:jkr
ID: 9773028
Addition - this is the same value that teh task manager shows in the 'Virtual Memory' column for each process.
0
 

Author Comment

by:lost_bits1110
ID: 9773069
okay thanks, so basically no matter where I get the value  of 'ms.dwTotalVirtual', it will return the virtual memory that my program is using?
0
 
LVL 86

Expert Comment

by:jkr
ID: 9773112
Yes :o)
0
 

Author Comment

by:lost_bits1110
ID: 9773132
Also, I just tried this and its telling me my code is running 2 Gigs of memory..!???? This doesnt make any sense.. this is the number i get:
 2147352576
0
 
LVL 86

Accepted Solution

by:
jkr earned 520 total points
ID: 9773186
Ooops, sorry *blushing* - you have to subtract the available bytes, so


cout<<ms.dwTotalVirtual-ms.dwAvailVirtual;

0
 

Author Comment

by:lost_bits1110
ID: 9773351
okay thanks.. i now get about 66293760 which is about 65 MB..? I wonder if this makes sense because I'm using the vtk graphics library, and i input a file that is about 8 Megs and my code is not that long really, and i've allocated a few small int arrays here and there etc..
So 65 MB still seems much? Or does this make sense??

so now if i want to get the value in kB lets say, I divided (ms.dwTotalVirtual-ms.dwAvailVirtual)/(2^10) but I get an incorrect value of: 8286720  when it really should be 64,740..?

Maybe its to do with the fact that its DWORD?
0
 

Author Comment

by:lost_bits1110
ID: 9773398
ok nevermind it works if i divide by 1024..

but do u think 64 Megs could make sense?  My biggest array has 76906 elements, theres an 8Meg file input, and a few ohter small integer arrays.. and i'm using a graphics library..
0
 
LVL 86

Expert Comment

by:jkr
ID: 9773630
>>but do u think 64 Megs could make sense?

Yes. Remember, it is not only your code, but also all system DLLs you are using that are being mapped into your program's address space.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question