3. Using MTS on Linux¶
3.1 Introduction¶
This chapter contains information specific to the Linux platform. For general information on MTS, see Chapter 2. MTS Basics. For information on building and executing the MTS demo programs, see Appendix A. Building the MTS Demo Programs
3.2 Release Contents¶
MTS for Linux consists of the following files:
Filename | Description |
---|---|
release_notes | Information on this release of MTS |
Makefile | Makefile for creating the demos |
demo.cc | 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 |
libmts64.so | MTS allocator shared library, 64-bit |
libmts64.a | MTS allocator static library, 64-bit |
disable/ | |
libmts.so | Shared 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. |
3.3 Enabling MTS Without Relinking¶
Systems that support the LD_PRELOAD
environment variable can use MTS
for dynamically-linked applications without relinking the application. A dynamically
linked application will automatically use MTS if the first library
in the LD_PRELOAD
variable is one of the MTS libraries. Note that multithreaded
versions of MTS require that the pthreads library (typically located
at /usr/lib/libpthread.so
) appear as the second library in
the LD_PRELOAD
variable. Note that multithreaded applications must not
preload a single-threaded library. See Appendix B for examples.
3.4 Linking to MTS¶
To link an application to MTS, include the appropriate MTS library as the first library on the link line. For example, the link line for the demo program that uses the multithreaded MTS fast allocator shared library is:
gcc -pthread demo.c mtsinstall/libstsm32.so
Note the use of the -pthread
flag instead of -lpthread
. It tells gcc to
use the correct preprocessor flags. In the sample above, replace mtsinstall
with the directory that contains the MTS libraries.
3.5 Using MTS Within C++ Applications (g++)¶
The C++ compiler within GCC (g++) uses a custom allocator by default
which pools memory allocated by the Standard C++ Library. The custom
allocator does not use MTS by default. To redirect the custom allocator
to MTS for improved application performance and scalability, define the
GLIBCPP_FORCE_NEW
environment variable before running the application
linked to MTS if using a version of GCC prior to 3.4 or GLIBCXX_FORCE_NEW
otherwise.
A permanent redirection of operator new to malloc() has to be done by overriding the default allocator for the Standard C++ Library containers or structures in use within the application. For more information regarding this topic, please see: