matlab mxcalloc函数语法

发表matlab mxcalloc函数相关文章
一句话说明: Allocate dynamic memory for array, initialized to 0, using MATLAB memory manager

mxCalloc (C and Fortran)

Allocate dynamic memory for array, initialized to 0, using MATLAB memory manager

C Syntax

#include "matrix.h"
#include <stdlib.h>
void *mxCalloc(mwSize n, mwSize size);

Fortran Syntax

mwPointer mxCalloc(n, size)
mwSize n, size

Arguments

n

Number of elements to allocate. This must be a nonnegative number.

size

Number of bytes per element. (The C sizeof operator calculates the number of bytes per element.)

Returns

Pointer to the start of the allocated dynamic memory, if successful. If unsuccessful in a MAT or engine standalone application, mxCalloc returns NULL in C (0 in Fortran). If unsuccessful in a MEX-file, the MEX-file terminates and control returns to the MATLAB® prompt.

mxCalloc is unsuccessful when there is insufficient free heap space.

Description

mxCalloc allocates contiguous heap space sufficient to hold n elements of size bytes each, and initializes this newly allocated memory to 0. Use mxCalloc instead of the ANSI® C calloc function to allocate memory in MATLAB applications.

In MEX-files, but not MAT or engine applications, mxCalloc registers the allocated memory with the MATLAB memory manager. When control returns to the MATLAB prompt, the memory manager then automatically frees, or deallocates, this memory.

How you manage the memory created by this function depends on the purpose of the data assigned to it. If you assign it to an output argument in plhs[] using the mxSetPr function, MATLAB is responsible for freeing the memory.

If you use the data internally, the MATLAB memory manager maintains a list of all memory allocated by the function and automatically frees (deallocates) the memory when control returns to the MATLAB prompt. In general, we recommend that MEX-file functions destroy their own temporary arrays and free their own dynamically allocated memory. It is more efficient to perform this cleanup in the source MEX-file than to rely on the automatic mechanism. Therefore, when you finish using the memory allocated by this function, call mxFree to deallocate the memory.

If you do not assign this data to an output argument, and you want it to persist after the MEX-file completes, call mexMakeMemoryPersistent after calling this function. 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.

Examples

See the following examples in matlabroot/extern/examples/mex.

See the following examples in matlabroot/extern/examples/refbook.

See the following examples in matlabroot/extern/examples/mx.

See Also

mexAtExit, mexMakeArrayPersistent, mexMakeMemoryPersistent, mxDestroyArray, mxFree, mxMalloc, mxRealloc

欢迎转载,转载请注明来自一手册:http://yishouce.com/matlab/func/mxcalloc

与matlab mxcalloc用法相关的文章

友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1