User Guide

Quick Start
Side Panel
Output Window
Graph View
App Toolbar
Launch Dialog
Connect Dialog
Snapshot Toolbar
Full Snapshot
Snapshot Views
Call Tree View
Call Tree Grouping
Memory View
Functions View
Types View
Leaks View
Tools Toolbar
Subtract Snapshots
Rewind Memory
VMem View
Settings Toolbar
Symbol Paths Dialog
MemPro Unix/GCC
PureDev Logo MemPro logo
C++ Memory Profiler


To allow MemPro to connect with your application you must compile your app with the MemProLib code and call the tracking functions when allocating memory. There are three main ways you can do this:

  1. Include MemPro.cpp in one of your source cpp files
  2. Compile and Link against the MemProLib.lib
  3. Link with MemProDll.dll

The MemProLib library can be found in the source code installation folder that was set in the installation, the default is:
C:\Program Files\PureDevSoftware\MemPro

Note: if you are profiling an application with multiple dlls you must use option 3 and link MemProDll.dll.

1. Including MemPro.cpp

This is the recommended way of embedding the code. It is simple, and easy to comment out when not needed. It is also the most portable solution.

Add these three lines of code to your main cpp source file:

//#define WAIT_FOR_CONNECT true
#include "MemPro.cpp"

(yes, you are including the cpp file)

the cpp file can be found here:
C:\Program Files\PureDevSoftware\MemPro\MemProLib\src

The WAIT_FOR_CONNECT line is optional. If defined to true your application will block on startup until MemPro has connected. This allows you to be sure that you are tracking every single allocation.

And that's it!

2. Linking to the MemProLib library

If you prefer to link to the MemPro library, include the MemPro.hpp in your main.cpp

//#define WAIT_FOR_CONNECT true
#include "MemPro.hpp"

And link to one of the pre-built libraries in the lib folder.

The header file can be found here:
C:\Program Files\PureDevSoftware\MemPro\MemProLib\src

The lib files can be found here
C:\Program Files\PureDevSoftware\MemPro\MemProLib\lib

If none of the pre-built libraries are suitable you can build your own MemProLib from the source code in the src file. MemProLib builds on virtually any platform and OS. The MemProLib source code can be found here:
C:\Program Files\PureDevSoftware\MemPro\MemProLib\src

3. Linking to the MemProLib Dll

Add these two lines to a cpp source file in each dll that you want to profile

Include "MemProDll.hpp"

Copy the MemProDLL.dll file to your exe directory.

The header file can be found here:
C:\Program Files\PureDevSoftware\MemPro\MemProDll\include

The dll and lib files are here:
C:\Program Files\PureDevSoftware\MemPro\MemProDll\bin

MemProDll.hpp includes a pragma telling the linker to link to MemProDll.lib. This adds a dependency to the dll. Please make sure the linker can find the lib file by adding the necessary path or modifying the pragma.

Note: Make sure that MemProDll.hpp is included only _once_ in each dll. Put it in the main source file, do not put it into a header that is included in multiple places.

Include and Library Paths

The installer automatically adds the include and library paths to the INCLUDE and LIB environment variables. However, the IDE does not use these variables unless run with the /useenv command line switch. So you'll probably want to add the path in the global property sheet in the IDE.

If you have already overridden new and delete

In the above solutions the OVERRIDE_NEW_DELETE define tells MemPro to override new and delete with its tracking hooks inserted. If you have already overridden new and delete (maybe for your own memory manager) you will need to insert the MemPro hooks into your overridden functions:

Include MemPro.cpp as before but don't define OVERRIDE_NEW_DELETE. Instead use the MemPro::TrackAlloc and MemPro::TrackFree functions

#include "MemPro.hpp" // or MemProDll.hpp if linking to MemProDll.dll

bool g_WaitForConnect = false;

void* operator new(size_t size)
void* p = YourInternalAlloc(size);
MemPro::TrackAlloc(p, size, g_WaitForConnect);
return p;

void operator delete(void* p)
MemPro::TrackFree(p, g_WaitForConnect);

void* operator new[](size_t size)
void* p = YourInternalAlloc(size);
MemPro::TrackAlloc(p, size, g_WaitForConnect);
return p;

void operator delete[](void* p)
MemPro::TrackFree(p, g_WaitForConnect);

The g_WaitForConnect bool specifies whether the call blocks until the MemPro app has connected. This is useful for making sure absolutely every allocation is being tracked.

What if I can't use a winsock connection in my app?

MemProLib uses a winsock TCP connection to communicate with MemPro. If for some reason this isn't possible in your application (no network connection for example) then you can still use MemPro.

Instead of connecting to your application over TCP you can tell MemProLib to write out a dump file of all allocations. This dump file can then be opened in MemPro and analyised just like any other mempro file. To enable allocation dumping uncomment this line in MemPro.hpp

//#define WRITE_DUMP _T("allocs.mempro_dump")

When this define is enabled the specified file will be created and all operations will be written to this file instead of being set over the network. The define also removes any dependency on windows sockets, so you should be able to use it in any environment. This file can get pretty big, so please ensure you have enough disk space.

Note: To avoid linker errors when overriding new/delete, make sure that MemPro.cpp is included before any system headers that also override new/delete. You may need to turn off any pre-compiled headers for that file. You may also need to do a full re-compile of your app to avoid multiple defined new and delete function warnings.

If you have any problems setting up MemProLib:

© Copyright 2011 - 2013 Stewart Lynch