locked
How to profile memory usage in a C++ application with Visual Studio

    Question

  • Hi everybody

     

    I know how to profile performance in a C++ application.

    I saw articles how to profile memory allocation in a .NET application.

    I have a task now to reduce memory consumption by a C++ application.

    And I have to write my own code or to use common tools like Perfmon.

     

    Is there any memory profiler for C++ applications?

    It would be good if such existed in Visual Studio.

    Why I cannot find it in VS?

    Thursday, May 29, 2008 7:38 AM

Answers

  •  

    The Visual Studio profiler is only able to collect object allocation and memory lifetime information for managed objects, so if you're working with a pure native app (which I assume you are here) the profiler won't be able to give you information on its memory usage.

     

    Of course you can still gather regular performance information on native apps, but unfortunately that doesn't help you in seeing where your memory is being used by your native app.

     

    Tim

    Thursday, May 29, 2008 10:18 PM
    Moderator

All replies

  •  

    The Visual Studio profiler is only able to collect object allocation and memory lifetime information for managed objects, so if you're working with a pure native app (which I assume you are here) the profiler won't be able to give you information on its memory usage.

     

    Of course you can still gather regular performance information on native apps, but unfortunately that doesn't help you in seeing where your memory is being used by your native app.

     

    Tim

    Thursday, May 29, 2008 10:18 PM
    Moderator
  • Hi Tim

     

    Thank you for your clear answer.

     

    Could you, please, shed some light why Visual Studio profiler does not have such a feature?

    May be the reason is in that the memory profiling in C++ applications is not widely needed?

     

    Oleg

     

    Tuesday, June 03, 2008 7:41 AM
  • Simply put, we do not currently have the resources to create and maintain a native memory profiler.

     

    Managed memory profiling is critical because of .NET's garbage collector and the lack of control that developers have over managing memory.  What was once a correctness issue (freeing everything allocated, not double freeing, who owns what memory, etc) has become a performance issue that can manifest itself as a disk or CPU issue.  Because of this, it's important that we give insight into the memory profile of managed applications.

     

    Regards,

    Chris

    Wednesday, June 11, 2008 10:48 PM
    Moderator
  • There is an article named "Design and Implementation of an In-Game Memory Profiler" in the book "Game Programming Gems 8" that provide an implementation of a memory allocation profiler on Windows. A preview of the article is avaliable online at http://my.safaribooksonline.com/9781584507024/ch37 , and the source code should came along with the book's companion CD.

    Note that the profile is not just able to find memory leaks, but it's able to show the memory usage in a hierarchical call-stack view. Moreover, a remote GUI viewer is avaliable for real-time monitoring with little effort.
    Wednesday, March 17, 2010 2:15 AM
  • Hi,

    Is there a way to profile memory for VC++ component(dll) that is been used as interop in C#.Net applications?

    Also I want to see the memory allocation for VC++ component(dll) used in C#.Net component which is consumed by VB6 appliation through COM.

     

    Thanks,

    Pradeep

    Sunday, December 04, 2011 5:42 PM
  • Hi,

    You might find my native profiler MemPro to be of use. It's released as a free beta here www.puredevsoftware.com

    Stewart.

    Monday, March 05, 2012 9:39 PM