4. Using MTS on Microsoft Windows

4.1 Introduction

MTS for Windows supports Windows NT, Windows 2000, Windows XP and Windows 2003 platforms. This chapter describes features of MTS specific to MTS for Windows.

4.2 Release Contents

MTS for Windows consists of the following files:

Filename Description
release_notes.txt Information on this release of MTS
Makefile Makefile for creating the demos
demo.c MTS demo program
mts.h Header file for directly invoking MTS functions
MTSPoolObject.H C++ wrapper for the MTS Pool allocator compatible with the C++ std::allocator interface
cpp_wrapper.cpp C++ operator new and delete definitions for static libraries
setmts.exe Utility program to add or remove DLLs from existing dynamically-linked executables
mts_enable.cpp Enables use of MTS with MFC applications
libmts64.lib MTS allocator static link library
libmts64.dll MTS allocator dynamic link library
disable/  
libmts.dll dynamic link library that acts as a passthrough to the system allocator. Used for debugging or benchmarking dynamically linked applications
UserGuide/ This manual
index.html The entry point for this manual.

4.3 File Location Requirements

In order to use MTS with dynamically-linked applications, the MTS libraries that your application will use must either be in the same directory as the executable, or in one of the directories specified by the PATH environment variable. If you build a product that uses an MTS DLL, you must ship that DLL along with your product. Your product’s install procedure must install the DLL into the directory on the target system that contains the executable.

4.4 Setting PATH in a Command Prompt Window

To set the PATH in an individual command prompt window, use the set command as shown below:

prompt> set PATH=mtsinstall;%PATH%

Replace mtsinstall with the directory that contains the MTS DLLs. All subsequent commands in the command prompt window will use the new PATH setting.

4.5 Setting the PATH on Windows NT

To set the PATH on a per-user or per-system basis, choose Start | Settings | Control Panel. Double click System, then choose the Advanced tab. Click the Environment Variables button. To change the PATH for the current user, select the PATH variable in the ”User variables” list.

To change the PATH for the system, select the PATH in the ”System variables” list. The name and value of the variable appear in the text fields at the bottom of the window. Add a semicolon and the name of the MTS directory to the end of the variable value. Click Set to save the change. Click OK to close the Environment Variables window.

Changing the PATH through the system menu does not affect open command prompt windows or other programs that are currently running.

4.6 Setting the PATH on Windows 2000

To set the PATH on a per-user or per-system basis, choose Start | Settings | Control Panel. Double click System, then choose the Advanced tab. Click the Environment Variables button. To change the PATH for the current user, select the PATH variable in the ”User variables” list. To change the PATH for the system, select the PATH in the ”System variables” list. Click the Edit... button below the PATH you’ve selected. Add a semicolon and the name of the MTS directory to the end of the variable value. Click OK to close the Edit System Variable window. Click OK to close the Environment Variables window.

Changing the PATH through the system menu does not affect open command prompt windows or other programs that are currently running.

4.7 Setting the PATH on Windows XP/2003

To set the PATH on a per-user or per-system basis, choose Start | Control Panel. Double click System, then choose the Advanced tab. Click the Environment Variables button. To change the PATH for the current user, select the PATH variable in the ”User variables” list. To change the PATH for the system, select the PATH in the ”System variables” list. Click the Edit... button below the PATH you’ve selected. Add a semicolon and the name of the MTS directory to the end of the variable value. Click OK to close the Edit System Variable window. Click OK to close the Environment Variables window.

Changing the PATH through the system menu does not affect open command prompt windows or other programs that are currently running.

4.8 Adding MTS to Your Applications

MTS Linker options for Windows:

MFC Link Option Sample Compile and Link Lines
No /ML

cl /ML -c cpp wrapper.cpp

cl /ML yourapp.cpp cpp wrapper.obj mtsfs32.lib

No /MT

cl /MT -c cpp wrapper.cpp

cl /MT yourapp.cpp cpp wrapper.obj mtsfm32.lib

No /MD

cl /MD yourapp.cpp

setmts -d:mtsfm32.dll yourapp.exe

Yes /MD cl /MD yourapp.cpp mts enable.obj mtsfm32 imp.lib

Note: cpp_wrapper.obj is only necessary if C++ (new, delete) is being used in your application.

4.9 MTS with Dynamically-Linked Applications

To use MTS with dynamically-linked applications, compile the application and then use the setmts.exe utility to add MTS to the application. In effect, the utility patches an existing executable to use the MTS library. The utility can also remove a patch applied to an executable. Note that the application must be compiled with the /MD flag to use the MTS library.

The command line for the setmts.exe utility has the following format:

setmts.exe [options] executable file

The utility accepts the options listed in the following table:

Argument Effect
-d:file.dll Updates the executable file specified to load file.dll
-r Removes any DLLs added by setmts.exe
-? Print a usage message

For example, the command lines below are a simplified version of the procedure the sample Makefile uses to produce the demoF.exe executable. The Makefile first compiles the demo program without MTS. The Makefile then copies the demo executable and uses setmts.exe to set the copy named demoF.exe to use the fast library:

prompt> cl.exe /nologo /Ox /MD demo.c /FedemoM.exe
prompt> copy demoM.exe demoF.exe
prompt> setmts -d:mtsfm32.dll demoF.exe

Note that the command lines above show only the flags that are common to applications using MTS. The actual Makefile may define macros used within the demo application.

4.10 Using MTS with Statically-Linked Applications

To create a statically-linked application, the link line should include the appropriate MTS library file. Multithreaded applications must be compiled with the /MT flag. Singlethreaded applications must be compiled with the /ML flag. For example, the sample Makefile uses the following compiler flags to compile and link the demoF.exe executable:

prompt> cl.exe /nologo /Ox /MT demo.c \
mtsinstall\mtsfm32.lib /FedemoF.exe

In the sample above, replace mtsinstall with the directory into which MTS is installed. Note that the command lines above show only the flags that are meaningful to the compiler. The actual Makefile may define macros used by the demo application. When using C++ operators new and delete within your statically-linked application you’ll also need to compile and link in cpp_wrapper.cpp. This file contains definitions for operator new and operator delete.

prompt> cl.exe /Ox /MT -c mtsinstall\cpp wrapper.cpp
prompt> cl.exe /Ox /MT yourapp.cpp cpp wrapper.obj \
mtsinstall\mtsfm32.lib

4.11 Using MTS with MFC Applications

To use MTS with an MFC application build the file mts_enable.obj in the following manner:

prompt> cl /MD -c mtsinstall\mts enable.cpp

Then add mts_enable.obj followed by mtsfm32_imp.lib to the link line of the MFC application.