Link to home
Start Free TrialLog in
Avatar of JonasRoden
JonasRoden

asked on

How much memory?

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.
ASKER CERTIFIED SOLUTION
Avatar of Arvindtn
Arvindtn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nils pipenbrinck
nils pipenbrinck

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.
Hi,
 I think the usage of SPY utility that comes along with the Visual Studio is the best option.

Bye
Abdij
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);
}
Avatar of JonasRoden

ASKER

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++ ?


/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
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
Sorry

It was ufolk123's answear I should have accepted.
How do I correct this error???
Hi,
 Please take some time before blindly accepting. Now you have to post a request at help desk i suppose. https://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
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

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