MATLAB Application Program Interface Reference Help Desk

mxSetAllocFcns

Purpose

Register your own memory allocation and deallocation functions in a stand-alone engine or MAT application

C Syntax

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:

void * callocfcn(size_t nmemb, size_t size);

nmemb

The number of contiguous elements that you want the matrix library to allocate on your behalf.

size

The size of each element. To get the size, you typically use the sizeof operator or the mxGetElementSize routine.

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);

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:

void * reallocfcn(void *ptr, size_t size);

ptr

Pointer to beginning of the memory parcel to reallocate.

size

The size of each element. To get the size, you typically use the sizeof operator or the mxGetElementSize routine.

mallocfcn

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:

void * mallocfcn(size_t size);

size

The size of each element. To get the size, you typically use the sizeof operator or the mxGetElementSize routine.

The mallocfcn you specify doesn't necessarily 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

Writing your own callocfcn, freefcn, and reallocfcn allows you to customize memory allocation and deallocation.

Example

See mxSetAllocFcns.c in the mx subdirectory of the examples directory.

See Also

mxCalloc, mxFree, mxRealloc



[ Previous | Help Desk | Next ]