From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is It Possible To Get Array Size From An Array Reference?

Solved!
Go to solution

P.S. - The trick I gave above for counting the number of array elements also works for figuring out how many elements are in a cluster.
cluster.png

Message 11 of 13
(692 Views)

@Darren wrote:

cluster.png


For arrays, it may be important to keep in mind that an Array Variant is not the same thing as an Array of Variants.  The Variant to Data function will happily give the old college try to convert datatypes that are compatible.  This means it will dutifully go through your original array, element by element, and create a variant for each one, and build that into an array.  If that sounds like it may be slow, it is.  That function is about 50-100X slower when converting to an array of variants than it is converting to the exact underlying array datatype.  With large arrays, that is a steep price to pay to just get the length.

 

If there were only small arrays, and a lot of different datatypes involved, I might use this 'shortcut'.  Otherwise I would use GetArrayInfo.vi  to figure out the array element type, and then use a case structure to do a direct conversion to the correct type and grab the length.  Pretty straightforward, and I doubt your eyes will bleed looking at it. 

 

If your clusters are so large that it starts to slow down this function, then you have other issues and need to get help immediately.  There is already a GetClusterInfo VI in vi.lib and on the pallete, so that is how I would roll.

 

Message 12 of 13
(672 Views)

@Darin.K wrote:

If there were only small arrays, and a lot of different datatypes involved, I might use this 'shortcut'.  Otherwise I would use GetArrayInfo.vi  to figure out the array element type, and then use a case structure to do a direct conversion to the correct type and grab the length.  Pretty straightforward, and I doubt your eyes will bleed looking at it. 


Yeah, if there's a finite number of array types you're expecting, that's what I would do too. But if you don't know what type the array element could be, my suggestion is the most general approach, and hopefully your arrays aren't so big that performance becomes an issue.

Message 13 of 13
(667 Views)