03-09-2022 09:39 AM
Hi!
I'm trying to understand two things: The exact purpose of the in-place element structure (I mean I can read the help context, but it says "in some cases" --> which ones?) and what difference does it make in a very specific case like the example below:
At program startup, I'm initializing some arrays (and obtaining clusters of queues and other stuff) and these arrays/clusters will change over time through development and I don't really want to have to change re-code my initialization process, so I'm trying to use FOR loops as much as possible; And basically I'm wondering if these 3 options are somehow performing/acting differently.
(This is just an example, thus the select case to show that some elements will never change (sometimes not be an array etc.)
Thank you in advance for your help 🙂
Vinny
Solved! Go to Solution.
03-09-2022 10:06 AM
Your two top loops will result in a 8 element array each, the third one will result in a 6 element array.
The memory management in LV is generally very good, so in this case the top two loops will probably be identical after compilation.
An example where i've benefitted much from a IPS-solution was when i had an array of clusters (a few hundred) which included some semi large arrays (~100k elements). Indexing out data was surprisingly heavy (due to data copy). Using a IPS it only copied the data i needed which made a big difference.
03-09-2022 10:27 AM
@Yamaeda wrote:
Your two top loops will result in a 8 element array each, the third one will result in a 6 element array.
Hmmm I'm not following you ... My array is made of 6 elements, so array size will be 6, so 6 iterations .... No?
@Yamaeda wrote:An example where i've benefitted much from a IPS-solution was when i had an array of clusters (a few hundred) which included some semi large arrays (~100k elements). Indexing out data was surprisingly heavy (due to data copy). Using a IPS it only copied the data i needed which made a big difference.
Ahhh I see, ok I'm not very familiar with memory management (I didn't know that indexing was copying the whole array), I know so Dos and Don'ts, but that's about it for now.
I'm not dealing with that massive arrays of data for now, so I guess it won't be a big issue for me for now, but good to know for later, thanks!
Vinny
03-09-2022 11:03 AM - edited 03-10-2022 09:00 AM
All three versions are basically identical once the compiler optimizations has digested and processed the code. All seem to have the same number of allocation dots.
Using the IPE is pointless, because you have no interest in the existing element. It is useful if you want to e.g. add the new element to the existing element.
Option 1 and 2 will guarantee that the output is of the same size as the input, even if N is less than the size. In that case, only the first N element will be replaced. If N is larger than the array size, no additional elements can be added. Option 3 will always give you 6 new elements, so it depends what you want.
There are of course optimizations outside your focus. For example the unbundling/rebundling could be done with an IPE.
Unless these data structures are gigantic, use the version with the simplest, most readable and maintainable code.
03-10-2022 02:21 AM
Thanks for the details Christian, much appreciated.
I'll go with the simplest as my structures are very simple and human readable.