Using the C Math Library    

Replacing Allocation and Deallocation Routines

The MATLAB C Math Library calls mxMalloc to allocate memory and mxFree to free memory. These routines in turn call the standard C runtime library routines malloc and free.

If your application requires a different memory management implementation, you can register your allocation and deallocation routines with the MATLAB C Math Library by calling the function mlfSetLibraryAllocFcns().

You must write four functions whose addresses you then pass to mlfSetLibraryAllocFcns():

    Your function should initialize the memory it allocates to 0 and should return NULL for requests of size 0.

    Make sure your function handles NULL pointers. free_fcn(0) should do nothing.

    This function must grow or shrink memory. It returns a pointer to the requested amount of memory, which contains as much as possible of the previous contents.

    Your function should return NULL for requests of size 0.

Refer to the MATLAB Application Program Interface Reference online help for more detailed information about writing these functions.


 Restrictions Indexing into Arrays