# Linux C/C++ Dynamic Memory Interface Replacement

Replacements are provided by the proxy library (release version `libtbbmalloc_proxy.so.2`, debug version `libtbbmalloc_proxy_debug.so.2`). Replacement can be done either via loading the proxy library at run-time (without changing of executable file via `LD_PRELOAD`), or by linking with the proxy library.

The proxy library implements the following dynamic memory functions:

- C library: `malloc`, `calloc`, `realloc`, `free`

- Standard POSIX* function: `posix_memalign`

- Obsolete functions: `valloc`, `memalign`, `pvalloc`, `mallopt`

- Global C++ operators `new` and `delete`.

A directory with the proxy library and the appropriate scalable memory allocator library must be available for dynamic loading. To make it available for loading, either include it in `LD_LIBRARY_PATH` or add it to `/etc/ld.so.conf`.

The following limitations for replacement exist:

- Replacement does not work for applications that use non-standard calls to the glibc memory allocator.

- Mono is not supported.

## Examples

Below is an example of how to set `LD_PRELOAD` and link a program to use the replacements.

    # Set LD_PRELOAD so that loader loads release version of proxy
    LD_PRELOAD=libtbbmalloc_proxy.so.2
    # Link with release version of proxy and scalable allocator
    g++ foo.o bar.o -ltbbmalloc_proxy -ltbbmalloc -o a.out

Here is a variation that shows how to link in the debug versions of the library.

    # Set LD_PRELOAD so that loader loads debug version of proxy
    LD_PRELOAD=libtbbmalloc_proxy_debug.so.2
    # Link with debug version of proxy and scalable allocator
    g++ foo.o bar.o -ltbbmalloc_proxy_debug -ltbbmalloc_debug -o a.out

Parent topic: Automatically Replacing malloc and Other C/C++ Functions for Dynamic Memory Allocation