The following tip has been on my list of possible nuggets for a while, but since it has <a href="
http://www.yqcomputer.com/ " target="_blank">recently been discussed on LAVA</a>, I figured I should go ahead and mention it before it becomes old news. :) It's basically a faster way to accomplish the following:
<img src="
http://www.yqcomputer.com/ ">
You see here that we have a data structure where objects are identified by their names. We could probably make this code easier to read (and possibly faster) by maintaining a separate array of the names and simply searching that array with Search 1D Array:
<img src="
http://www.yqcomputer.com/ ">
Both of these methods are inherently linear searches. It turns out that the following method of accessing the data is much faster:
<img src="
http://www.yqcomputer.com/ ">
I had never given much thought to Variant Attributes until this trick was shown to me. You can basically store each data object as a different attribute of some dummy variant. I say it's a "dummy" variant because its actual value and datatype are inconsequential...we're purely using the variant to gain access to its attributes as a data store. I'm no computer scientist, but apparently the variant attributes are stored using a "<a href="
http://www.yqcomputer.com/ " target="_blank">red/black tree</a>" algorithm, which ends up being an order log(n) search...this is much faster than an order n search, which is what the While Loop or Search 1D Array approach would be.
So the next time you find yourself creating a string array lookup similar to one of the two traditional approaches above, try giving the Variant Attribute approach a try. Note that this approach is recommended for LabVIEW 8.0 and later, due to some performance improvements with variants that did not exist in LabVIEW 7.1 and previous.
-D P.S. - Check out past nuggets <a href="
http://www.yqcomputer.com/ ;message.id=1669" target="_blank"> here</a>. Message Edited by Darren on 10-09-2006 11:14 AM
variant_attribute.jpg:
http://www.yqcomputer.com/
while_loop.jpg:
http://www.yqcomputer.com/
search_1d.jpg:
http://www.yqcomputer.com/