Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Using Arrays in the Function Prototype (C Generator)

LabVIEW 2011 C Generator Help

Edition Date: June 2013

Part Number: 373144C-01

»View Product Info

The LabVIEW C Generator supports arrays as parameters of the exported VI prototype. You can use array pointers or LabVIEW arrays to pass data in an exported VI function. A length parameter for both inputs and outputs follows the 1D array parameter. For an array, the length is the total number of elements in the array.

Array Pointers

When you use array pointers to pass 1D arrays, the prototype includes pointers to data elements and the length. For example, a 1D array of doubles is represented as a float64 * and an int32 length parameter.

When you use array pointers to pass multi-dimensional arrays, the C Generator creates the following struct, which contains pointers to the data elements and the dimension size.

typedef struct {

   int32 dimSizes[2],

   float64 *elemArr;   //In this case, a 2D array of doubles.

} TD1;

In the Define VI Prototype dialog box, select the array in the Parameters list and set the Pass By option to Array Data Pointer to use array pointers. When you use array pointers to pass data, LabVIEW creates an internal copy of the array.

LabVIEW Arrays

Use LabVIEW arrays to avoid creating an extra copy of the array in the exported VI function. When you use LabVIEW arrays to pass data, the C Generator creates the following struct. This struct is defined in the VINameLib.h file, where VIName is the name of the exported VI.

typedef struct {

   uInt32 res1;

   int16 res2;

   uInt8 res3;

   uInt8 res4;

   uInt32 numDims;

   ArrDimSize dimSizes[2];   //In this case, a 2D array of doubles

   float64 elemArr[1];

} LvArr1, *LVArr1Hdl;

In the Define VI Prototype dialog box, select the array in the Parameters list and set the Pass By option to LV Array to use LabVIEW arrays.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit