Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Want to determine how much total memory my code uses?

Posted on 2003-11-18
12
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

715 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