?
Solved

How much memory?

Posted on 2000-01-25
11
Medium Priority
?
203 Views
Last Modified: 2012-05-04
I'm developing a C++ program i MSVC++ and would like to see how much memory
my program uses.
How do I get a file which presents the actual amount of memory used by my global and static variables?
I don't use any dynamik allocations.
0
Comment
Question by:JonasRoden
11 Comments
 

Accepted Solution

by:
Arvindtn earned 400 total points
ID: 2384895
  Simple, Execute your program, minimize it and goto Task Manager, click the Process tab, In that screen you will find a column "Mem Usage", which displays the actual memory used by your .exe file.

   The best way to find the amount of memory used by you variable is as follows.

  If you have declared variables as follows

  int i;
  float f;

The memory occupied by the variable i and f would be
   = ( sizeof(i) + sizeof(f) )


0
 
LVL 4

Expert Comment

by:nils pipenbrinck
ID: 2384915
ehm.. compile it and take a look at the map file.. there is a segment or section summary which tells you exactly how many bytes you used.
0
 
LVL 2

Expert Comment

by:abdij
ID: 2384926
Hi,
 I think the usage of SPY utility that comes along with the Visual Studio is the best option.

Bye
Abdij
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 3

Expert Comment

by:akalmani
ID: 2384943
Hi JonasRoden !!

  This gives in general what memory is being used by u r program

  Hope this helps !!


// A short program showing the return values of
// GlobalMemoryStatus. Warning: There is no error checking. #include <windows.h>
// The divisor and the string following appear this way so you can
// easily change the divisor from K to MB or any unit you want. #define DIV 1024
char *divisor = "K";
voidmain(int argc, char *argv[]){
  MEMORYSTATUS stat;
  GlobalMemoryStatus (&stat);
  printf ("The MEMORYSTATUS structure is %ld bytes long.\n",
      stat.dwLength);  printf ("It should be %d.\n", sizeof (stat));
  printf ("There is %ld percent of memory in use.\n",      stat.dwMemoryLoad);
  printf ("There are %ld total %sbytes of physical memory.\n",
      stat.dwTotalPhys/DIV, divisor);
  printf ("There are %ld free %sbytes of physical memory.\n",
      stat.dwAvailPhys/DIV, divisor);
  printf ("There are %ld total %sbytes of paging file.\n",
      stat.dwTotalPageFile/DIV, divisor);
  printf ("There are %ld free %sbytes of paging file.\n",
      stat.dwAvailPageFile/DIV, divisor);
  printf ("There are %ld total %sbytes of virtual memory.\n",
      stat.dwTotalVirtual/DIV, divisor);
  printf ("There are %ld free %sbytes of virtual memory.\n",
      stat.dwAvailVirtual/DIV, divisor);
}
0
 

Author Comment

by:JonasRoden
ID: 2385310
I didn't expres my self clear enough.

I would like a map file, which
informs me about the memoty used.

How do I get a map file from MSVC++ ?


0
 
LVL 3

Expert Comment

by:ufolk123
ID: 2387672
/Fm (Name Map File)


The /Fm[filename] option instructs the linker to produce a map file. No space is allowed between /Fm and filename. The map file contains a list of segments in the order of their appearance within the corresponding .EXE file or DLL. By default, the map file is given the base name of the corresponding C or C++ source file with a .MAP extension. If you specify the /c option to suppress linking, /Fm has no effect.

Global symbols in a map file usually have one or more leading underscores, because the compiler adds an underscore to the beginning of variable names. Many of the global symbols that appear in the map file are used internally by the compiler and the standard libraries.

For more information on map files, see the /MAP linker option.


ufolk123
0
 
LVL 2

Expert Comment

by:abdij
ID: 2395713
Hi Man,
 Whose answer did you like anyway????

arvindtn or ufolk123. I think it was ufolk123 who gave you the map file needed and you accepted arvindtn's answer or was it intentional???????????????????????????????????????????????????????????

Bye
Abdij
0
 

Author Comment

by:JonasRoden
ID: 2395730
Sorry

It was ufolk123's answear I should have accepted.
How do I correct this error???
0
 
LVL 2

Expert Comment

by:abdij
ID: 2395776
Hi,
 Please take some time before blindly accepting. Now you have to post a request at help desk i suppose. http://www.experts-exchange.com/Customer_Service/Experts_Exchange/.

When an expert can spend time to answer your question can you not spare seconds to see who has answered your question!!!!!!!!!!!!!!!!!!!!!!!!!!!

Or are you people so very very very busy and consider that we have no other work????????????????????????????????

Take care.

Bye
Abdij
0
 

Author Comment

by:JonasRoden
ID: 2395887
Hi,

I'm sorry for my mistake. I'm a first time user, that’s maybe no excuse but the reason.

Thanks for all answers, and again I'm sorry for any inconvenience

Bye
JonasRoden

0
 
LVL 5

Expert Comment

by:ianB
ID: 2411161
hi,

Since I cant direct the points without deleting the question, I have posted a question for ufolk123 in this topic area so he/she can claim the points some points for this question.

Ian
Community Support @ Experts Exchange
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

601 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