Synopsis

PDX_MSGT mda_GetArraySize(int type, void *array, long *size)

Purpose

Get size of an array.

Description

The size (in bytes) of the array at data will be returned. The array at data must have been allocated with mda_Malloc, mda_Calloc, mda_Realloc, or their array (mda_MallocArray, etc.) counterparts. If a value of NULL is specified, a size of 0 will be returned. The size is computed as the total number of elements in the array times the size of each element. It does not include the internal pointer information stored with arrays allocated with the mda_XxxxArray calls.

If array was allocated with mda_MallocArray, mda_CallocArray, or mda_ReallocArray, it CAN NOT be passed to this function as the address of the first element in the array. For example, given a field declared as "array[cnt1][cnt2]", it must be passed as "array", not "&array[0][0]". This also means that for arrays allocated with these functions, the data argument to a function called from mda_TraverseEntity can not be passed directly to this function. Instead, the following code should be used inside the function called from mda_TraverseEntity (this code will also work with arrays allocated via mda_Malloc, mda_Calloc, and mda_Realloc if the first parameter to mda_GetArraySize is changed from 2 to 1):

.nf void *data_addr; long size;

if (ddf_GetFieldInfo(fld) & DDF_UNSIZED) { if (ddf_GetFieldInfo(fld) & DDF_VARIABLE) { data_addr = mda_GetTraverseAddr (); mda_GetArraySize (2, *(char **) data_addr, &size); } } .fi

Input

type

How array was originally allocated. Specified as a 1 if array was allocated using mda_Malloc, mda_Calloc, or mda_Realloc. Specified as a 2 if array was allocated using mda_MallocArray, mda_CallocArray, or mda_ReallocArray.

array

Pointer to array

Output

size

Size in bytes of array

Return

MDA error code