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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

  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) )


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nils pipenbrinckCommented:
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.
 I think the usage of SPY utility that comes along with the Visual Studio is the best option.

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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[]){
  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);
JonasRodenAuthor Commented:
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.

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

JonasRodenAuthor Commented:

It was ufolk123's answear I should have accepted.
How do I correct this error???
 Please take some time before blindly accepting. Now you have to post a request at help desk i suppose.

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.

JonasRodenAuthor Commented:

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



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.

Community Support @ Experts Exchange
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.