| External Interfaces/API Reference | ![]() |
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
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:
The 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:
void freefcn(void *ptr); | |
|
Pointer to beginning of the memory parcel to deallocate. |
The 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:
mallocfcn
The name of the function that API functions call in place of 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. |
The mallocfcn you specify doesn't need to initialize the memory it allocates.
Description
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 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.
Writing your own callocfcn, mallocfcn, freefcn, and reallocfcn allows you to customize memory allocation and deallocation.
Examples
See mxsetallocfcns.c in the mx subdirectory of the examples directory.
See Also
mxCalloc, mxFree, mxMalloc, mxRealloc
| mxRemoveField | mxSetCell | ![]() |