C++ Math Library Reference    

Array Size

In MATLAB, the size() function returns the size of an array as an array. The MATLAB C++ Math Library provides a corresponding version of size() that also returns an array. Because this C++ version allocates an array to hold just two integers, it is not efficient. The mwArray Size member functions below return the size of an array more efficiently.

An array (a matrix is a special case) has two sizes: the number of its dimensions (for matrices, always two) and the actual size of each dimension. You can use these Size() functions to determine both the number of dimensions and the size of each dimension.

int32 Size() const

Return the number of dimensions. In this version of the library, this function always returns two.

int32 Size(int32 dim) const

Return the size (number of elements) of the indicated dimension. The integer argument to this function must be either 1 or 2.

int32 Size(int32* dims, int maxdims=2) const

Determine the sizes of all the dimensions of the array and return them via the given integer array, dims. maxdims is the maximum number of dimensions the function should return. The input integer array dims must contain enough space to store at least maxdims integers. If maxdims is less than the number of dimensions of the mwArray, the last dimension returned is the product of the remaining dimensions. This function's return value is the number of dimensions of the mwArray.


 Memory Management The mwVarargin and mwVarargout Classes