Please enable JavaScript to view this site.

Memory Validator Help

Navigation: Getting Started

Before you start

Scroll Prev Top Next More

This section details the requirements necessary to monitor C runtime (CRT) heap allocations, followed by sections specific to enabling debugging information for Visual Studio, C++ Builder, Delphi, MinGW, and other compilers.


If you are using Memory Validator to monitor C runtime (CRT) heap allocations, read on, and check you have the necessary run time library setup.


Once you're confident you have the required environment (CRT and debug info settings), skip to Quick Start.



CRT heap allocations


The gist of the rest of this section is that Microsoft compiler users should use a dynamically linked CRT library, or you may use a statically linked CRT provided you have a matching MAP file.


seeAlsoSupported compilers and linkers



Dynamic CRT linking


To track C runtime heap allocations, your program and/or dlls must be linked to the dynamic CRT in one of the following:




the equivalent depending on the version of Visual Studio e.g. msvcr70/71/80/90/100/110.dll

an alternative library for other compilers, as outlined in the Memory Hooks reference



Static CRT linking


If you are linked statically, to one of the following CRTs:


LIBC.LIB - single-threaded

LIBCD.LIB - single-threaded debug

LIBCMT.LIB  - multi-threaded

LIBCMTD.LIB - multi-threaded debug


then the CRT heap allocation tracking will function but performance will be slower than for the dynamically linked case.


However, in addition, you must generate MAP files for each EXE/DLL that you link statically to the C runtime. The MAP file should have the same name as the EXE/DLL but with the extension ".map", e.g. "example.dll" should have a corresponding MAP file "".


hmtoggle_plus0What are MAP files and why are they needed? MAP files are typically plain text files that indicate the relative offsets of functions for a given version of a compiled binary. They contain information about your program’s global symbols, source file and source line numbers. In the event of statically linked CRT libraries, Memory Validator falls back to using the MAP file to locate the functions. You can create the MAP file when linking your executable or DLL by setting certain options for the linker.  


hmtoggle_plus0Why is dynamic linking better? The reason for this is that Memory Validator uses the Import Address Table to provide hooks into MSVCRT.DLL. When you link statically the Import Address Table is not present and cannot be hooked. Most large applications are dynamically linked (based on our testing), but many small projects are often built statically. These statically linked projects need to be built using the dynamic library for best monitoring performance.  


note If using Borland compilers you can use Memory Validator to monitor memory allocations in a statically linked program. You'll be presented with the usual CRT warning dialog informing you that the use of the dynamic memory allocator could not be detected, but that can be ignored.



Which CRT am I using?


You can inspect (and change) the static/dynamic linking nature of your program:


Microsoft Developer Studio


Choose Project menu instructionStep Settings... instructionStep C++ tab on the dialog box instructionStep Using the Category combo box choose Code Generation.


If you are using the dynamic multi-threaded MSVCRT.DLL the following will be shown in the Use run-time library combo box (highlighted in red below).


Alternatively, if using the debug MSVCRTD.DLL, the same box will show Debug Multithreaded DLL.





Visual Studio e.g. VS9.0 (2008)


Choose Project menu instructionStep [ProgramName] Properties... instructionStep Configuration Properties in the list instructionStep C++ instructionStep Code Generation


If you are using the debug dynamic multi-threaded MSVCRTD.DLL the following will be shown in the Runtime Library option (highlighted in red below).


Alternatively, if using the non debug MSVCRT.DLL, the same box will show Multi-threaded DLL (/MD).





CRT Compiler options


The compiler options corresponding to the above choices are:


For dynamic multi-threaded CRT linking:








For static CRT linking:



LIBC.LIB - single threaded


LICD.LIB - single threaded debug


LIBCMT.LIB - multi-threaded


LIBCMTD.LIB - multi-threaded debug



Changing from static to dynamic CRT linking


To use dynamic linking you need to either select one of the selections shown in the pictures above, or use the /MD or /MDd compiler flags instead of /ML, /MLd, /MT, /MTd.


The following shows which option you should use when changing compiler options:

















If you are linked statically, you only need to make this change once and rebuild the application. If you are linked dynamically you do not need to rebuild your application.


note When rebuilding your DLL(s), you may get warning messages which refer to libraries used by the static linking which you are no longer using. This is caused by some default settings in your project. You can prevent these by disabling the linking of default libraries. You will then need to specify any libraries you require.


In Developer Studio, the image below shows the checkbox to select to prevent linking to the default libraries.




In Visual Studio 9.0 to show the same option:


 Choose Project menu instructionStep [ProgramName] Properties... instructionStep Configuration Properties in the list instructionStep Linker instructionStep Input instructionStep Ignore All Default Libraries



CRT Warning Dialog


When Memory Validator launches an application it checks to determine if the application is using the dynamic C runtime library (or equivalent).


If the dynamic CRT cannot be detected, a warning dialog is displayed to the user:




Don't panic! It looks worrying, but it's not! It is just a warning. You can still launch your application with Memory Validator.


Many applications do not use the dynamic CRT in the main .EXE, but do use it in the DLLs used by the application. In this case, Memory Validator will monitor CRT allocations in the DLLs, and will monitor non-CRT allocations (handles and other memory types) in the .EXE and the DLLs.


Lucky users of Borland compilers can build their applications statically linked or dynamically linked - either will work.