0

I have created an application in C++ using visual studio. And as per my application it should take very less memory but it is taking very much memory. So, now I want to know memory map function wise. Is there any way in Visual Studio to generate memory map or any other tool or any other way to generate memory map. Please Reply soon.

Thanks in Advance.

Mayank

Mayank Prabhakar
  • 133
  • 2
  • 6
  • 14

2 Answers2

1

You could try using Visual Leak Detector. It will not give you function wise memory usage but will highlight leaked memory traces in the debugger output. You'll have to play around a bit go get used to it.

mots_g
  • 637
  • 8
  • 27
0

I believe it is more operating system specific than language or compiler specific.

On Linux, you can read (from inside your process) the /proc/self/maps to understand the memory map of your application.

     % cat /proc/self/maps
    00400000-0040c000 r-xp 00000000 08:01 2334758                /bin/cat
    0060c000-0060d000 rw-p 0000c000 08:01 2334758                /bin/cat
    012fd000-0131e000 rw-p 00000000 00:00 0                      [heap]
    7f1714cf2000-7f1715009000 r--p 00000000 08:01 3932623        /usr/lib/locale/locale-archive
    7f1715009000-7f1715183000 r-xp 00000000 08:01 3892787        /lib/x86_64-linux-gnu/libc-2.13.so
    7f1715183000-7f1715383000 ---p 0017a000 08:01 3892787        /lib/x86_64-linux-gnu/libc-2.13.so
    7f1715383000-7f1715387000 r--p 0017a000 08:01 3892787        /lib/x86_64-linux-gnu/libc-2.13.so
    7f1715387000-7f1715388000 rw-p 0017e000 08:01 3892787        /lib/x86_64-linux-gnu/libc-2.13.so
    7f1715388000-7f171538d000 rw-p 00000000 00:00 0 
    7f171538d000-7f17153ac000 r-xp 00000000 08:01 3892902        /lib/x86_64-linux-gnu/ld-2.13.so
    7f1715589000-7f171558c000 rw-p 00000000 00:00 0 
    7f17155aa000-7f17155ac000 rw-p 00000000 00:00 0 
    7f17155ac000-7f17155ad000 r--p 0001f000 08:01 3892902        /lib/x86_64-linux-gnu/ld-2.13.so
    7f17155ad000-7f17155ae000 rw-p 00020000 08:01 3892902        /lib/x86_64-linux-gnu/ld-2.13.so
    7f17155ae000-7f17155af000 rw-p 00000000 00:00 0 
    7fff374d2000-7fff374f3000 rw-p 00000000 00:00 0              [stack]
    7fff3750c000-7fff3750d000 r-xp 00000000 00:00 0              [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0      [vsyscall]

The above example shows the memory map of the process executing the cat command.

EDIT

Don't expect to find memory use by function, since memory usage of a given data is a global property of the program (so the very notion of memory usage per function has no sense). You could use some garbage collection technique. And you could (at least on Linux) use Boehm's garbage collector, or write your own GC, or hunt memory leaks with valgrind (or a similar program for your system).

You have to find out if your operating system gives you an equivalent facility. (I don't know and don't use Windows, so I cannot help more)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Thanks for your reply.. Actually I am looking for function wise memory breakdown. I have used VTune but there is not any option in VTune to track function wise break down of memory(Like VTune shows for CPU TIME). For example my application is taking 5Mb (reported by Window's task manager) and I want to know that which function is taking how much memory. ( FYI There is no memory leak in my application as reported by VTune). – Mayank Prabhakar Dec 13 '11 at 13:03
  • The size listed in task manager will (I believe) be the size of the process space allocated, which will include the size of the generated program executable itself (how big is that?) and possible also the size of shared libraries it links against (what do you link with?). I think it's unlikely to be a good indicator of how much of the free store or stack space you've used in your program - particularly at a relatively low value like 5MB. – boycy Dec 13 '11 at 13:20