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

DNatt, LV R&D
Message 11 of 13
(232 Views)
Highlighted

@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
(212 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.

DNatt, LV R&D
Message 13 of 13
(207 Views)