Developer Guide

Contents

Redefining Memory Functions

In C/C++ programs, you can replace
Intel® MKL
memory functions that the library uses by default with your own functions. To do this, use the
memory renaming
feature.

Memory Renaming

Intel® MKL
memory management by default uses standard C run-time memory functions to allocate or free memory. These functions can be replaced using memory renaming.
Intel® MKL
accesses the memory functions by pointers
i_malloc, i_free, i_calloc
, and
i_realloc
, which are visible at the application level.
These pointers initially hold addresses of the standard C run-time memory functions
malloc, free, calloc
, and
realloc,
respectively.
You can programmatically redefine values of these pointers to the addresses of your application's memory management functions.
Redirecting the pointers is the only correct way to use your own set of memory management functions. If you call your own memory functions without redirecting the pointers, the memory will get managed by two independent memory management packages, which may cause unexpected memory issues.

How to Redefine Memory Functions

To redefine memory functions, use the following procedure:
If you are
using the statically linked
Intel® MKL
,
  1. Include the
    i_malloc.h
    header file in your code.
    This header file contains all declarations required for replacing the memory allocation functions. The header file also describes how memory allocation can be replaced in those Intel libraries that support this feature.
  2. Redefine values of pointers
    i_malloc, i_free, i_calloc
    , and
    i_realloc
    prior to the first call to
    Intel® MKL
    functions, as shown in the following example:
#include "i_malloc.h"   . . .   i_malloc  = my_malloc;   i_calloc  = my_calloc;   i_realloc = my_realloc;   i_free    = my_free;   . . . // Now you may call Intel MKL functions
If you are using the dynamically linked
Intel® MKL
,
  1. Include the
    i_malloc.h
    header file in your code.
  2. Redefine values of pointers
    i_malloc_dll, i_free_dll, i_calloc_dll
    , and
    i_realloc_dll
    prior to the first call to
    Intel® MKL
    functions, as shown in the following example:
#include "i_malloc.h"   . . .   i_malloc_dll  = my_malloc;   i_calloc_dll  = my_calloc;   i_realloc_dll = my_realloc;   i_free_dll    = my_free;    . . . // Now you may call Intel MKL functions

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804