08-09-2017 08:04 AM
Let's say I have an array of objects which themselves contain a number of children which contain a number of children and so on. While the top level object array might only contain a handful of elements, because of this hierarchical nesting, each of those elements could contain a fairly large amount of data. Is there any way to perform an operation such as checking if the array is empty or getting the number of elements without having to create a copy of the entire array or is there any optimization done by the compiler in such a case?
Solved! Go to Solution.
08-09-2017 08:22 AM
If you are just reading the values in a VI, you can use Index Array and a data copy will not be made. If you are doing updates, then look to the In Place Element Structure to make sure the compiler does not make the copies. Though, the compiler has gotten really good at handling read-modify-write setups for arrays without the IPES.
08-09-2017 08:29 AM
This wouldn't be read-modify-write. For sure, to make changes to an element of the array, the in place structure is then obvious candidate.
But something like this:
would still (I'm assuming) have to create a copy of the entire array yes?
08-09-2017 08:39 AM
@blackburnite wrote:
But something like this:
would still (I'm assuming) have to create a copy of the entire array yes?
No, it does not. You don't even need the In Place Element Structure there. Just because there is a branch does not necessarily mean you have created a data copy. The compiler is smart enough to avoid those data copies. When you start modifying the data in multiple branches is when data copies will occur.
08-09-2017
08:41 AM
- last edited on
05-05-2025
12:03 PM
by
Content Cleaner
It definitely shouldn't cause a data copy of the array, unless someone writing the LV made a horrible mistake.
LabVIEW stores the array with size information prepended in memory, so the "is array empty" should just check the value of the data size byte(s), no need to even look at the contents of the array.
Also checked the buffer allocation tool in LabVIEW for this case, it shows no new array buffers. You wouldn't need the IPE structure either.
After all, branching a wire doesn't necessarily mean a copy, it depends on what the wire is used for.
08-09-2017 08:42 AM
OK, excellent, that's what I wanted to know. I assumed compiler optimization would handle that but I haven't dug into it too in depth yet. thanks.