External Interfaces Reference Previous page   Next Page
mxMalloc

Allocate dynamic memory using MATLAB memory manager

Fortran Syntax

Arguments

n
   Number of bytes to allocate.

Returns

A pointer to the start of the allocated dynamic memory, if successful. If unsuccessful in a stand-alone (nonMEX-file) application, mxMalloc returns 0. If unsuccessful in a MEX-file, the MEX-file terminates and control returns to the MATLAB prompt.

mxMalloc is unsuccessful when there is insufficient free heap space.

Description

Use mxMalloc to allocate dynamic memory using the MATLAB memory management facility.

MATLAB maintains a list of all memory allocated by mxMalloc. MATLAB automatically frees (deallocates) all of a MEX-file's memory when the MEX-file completes and control returns to the MATLAB prompt.

If you want the memory to persist after a MEX-file completes, call mexMakeMemoryPersistent after calling mxMalloc. If you write a MEX-file with persistent memory, be sure to register a mexAtExit function to free allocated memory in the event your MEX-file is cleared.

When you finish using the memory allocated by mxMalloc, call mxFree. mxFree deallocates the memory.

Note that mxMalloc works differently in MEX-files than in stand-alone MATLAB applications.

In MEX-files, mxMalloc automatically:

See Also

mxCalloc, mxFree, mxDestroyArray, mexMakeArrayPersistent,
mexMakeMemoryPersistent


Previous page  mxIsUint64 mxRealloc Next page

© 1994-2005 The MathWorks, Inc.