| MATLAB Application Program Interface Reference | Help Desk |
mxSetAllocFcns
Register your own memory allocation and deallocation functions in a stand-alone engine or MAT application
#include "matrix.h" #include <stdlib.h> void mxSetAllocFcns(calloc_proc callocfcn, free_proc freefcn, realloc_proc reallocfcn, malloc_proc mallocfcn);callocfcn
The name of the function that mxCalloc uses to perform memory allocation operations. The function you specify is ordinarily a wrapper around the ANSI C calloc function. The callocfcn you write must have the prototype:
callocfcn you specify must create memory in which all allocated memory has been initialized to zero.
freefcn
The name of the function that mxFree uses to perform memory deallocation (freeing) operations. The freefcn you write must have the prototype:
freefcn you specify must contain code to determine if ptr is NULL. If ptr is NULL, then your freefcn must not attempt to deallocate it.
reallocfcn
The name of the function that mxRealloc uses to perform memory reallocation operations. The reallocfcn you write must have the prototype:
The size of each element. To get the size, you typically use the
|
|
The name of the function the API functions should call in place of malloc to perform memory reallocation operations. The mallocfcn you write must have the prototype:
The size of each element. To get the size, you typically use the
|
|
mallocfcn you specify doesn't necessarily need to initialize the memory it allocates.
Call mxSetAllocFcns to establish your own memory allocation and deallocation routines in a stand-alone (nonMEX) application.
It is illegal to call mxSetAllocFcns from a MEX-file; doing so causes a compiler error.
In a stand-alone application, if you do not call mxSetAllocFcns, then
mxCalloc simply calls the ANSI C calloc routine.
mxFree simply calls the ANSI C free routine.
mxRealloc simply calls the ANSI C realloc routine.
callocfcn, freefcn, and reallocfcn allows you to customize memory allocation and deallocation.
See mxSetAllocFcns.c in the mx subdirectory of the examples directory.
mxCalloc, mxFree, mxRealloc