Redefining Memory Functions
In C/C++ programs, you can replace memory functions that the library uses by default with your own functions. To do this, use the
Intel® oneAPI Math Kernel Library
memory renaming
feature.
Memory Renaming
Intel® oneAPI Math Kernel Library
Intel® oneAPI Math Kernel Library
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
You can programmatically redefine values of these pointers to the addresses of your application's memory management functions.
malloc, free, calloc
, and
realloc,
respectively.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:
- Include thei_malloc.hheader 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.
- Redefine values of pointersi_malloc, i_free, i_calloc, andi_reallocprior to the first call tofunctions, as shown in the following example:Intel® oneAPI Math Kernel Library
#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