| MATLAB Application Program Interface | Search  Help Desk |
| mxSetAllocFcns | Examples See Also |
Register your own memory allocation and deallocation functions in a stand-alone engine or MAT application
C Syntax
#include "matrix.h" #include <stdlib.h> void mxSetAllocFcns(calloc_proc callocfcn, free_proc freefcn, realloc_proc reallocfcn, malloc_proc mallocfcn);
Arguments
callocfcnmxCalloc 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
mxFree uses to perform memory deallocation (freeing) operations. The freefcn you write must have the prototype:void freefcn(void *ptr); | |
|
Pointer to beginning of the memory parcel to deallocate. |
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
mxRealloc uses to perform memory reallocation operations. The reallocfcn you write must have the prototype:malloc to perform memory reallocation operations. The mallocfcn you write must have the prototype:void * mallocfcn(size_t n); | |
|
The number of bytes to allocate. |
mallocfcn you specify doesn't need to initialize the memory it allocates.
Description
CallmxSetAllocFcns 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 calls a free function, which calls the ANSI C free routine if a NULL pointer is not passed.
mxRealloc simply calls the ANSI C realloc routine.
callocfcn, mallocfcn, freefcn, and reallocfcn allows you to customize memory allocation and deallocation.
Example
Seemxsetallocfcns.c in the mx subdirectory of the examples directory.
See Also
mxCalloc, mxFree, mxMalloc, mxRealloc