06-05-2013 06:18 AM - edited 06-05-2013 06:19 AM
Hi all,
I have a question regarding the use of the Always Copy function available in the memory palette and its uses within Labview applications. I have seen it use in VI's such as WDT Number of Waveform Samples DBL in the error case and I am assuming its to overwrite and clear the currently assigned memory in the instance of an error. I was wondering if other had used this function and in what was the remit for doing so? I have put together the example to try and create multiple references of cluster in memory and attempt to modify each instance using a pair of DVR's IPE but have had little success. I would like to stress this is for my understanding of the behaviour of the LV dev environment and not something I attempting to put together for a customer.
Many Thanks
06-05-2013 06:20 AM
Note: After the copy probes have shown the reference remains the same, also the code will error as there is no need to close the same ref twice in the for loop.
06-05-2013 06:47 AM
I think that the first misconseption is that the copy copy's the data. in this case it only copys the reference (pointer). next it will in this case not make a difference if the always copy is there or not for the splitting wire will copy the reference no mather what.
to copy the data you first need to extract the data from the cluster and copy this and then make a new reference for it.
Note: this is to my best of understanding of labview and computer programming in general.
06-05-2013 06:53 AM
Andy,
your code makes no sense.
You are using a DVR in order NOT to copy the basic data (cluster). You then copy the reference to the data (DVR) twice as the branch already creates a copy for the reference.
Granted: the compiler should be clever enough to reduce the number of instances of DVRs to two, so you would not waste additional 8 bytes.
But so or so, you never create a copy of the original data set, you cluster.
Recap:
- Always copy makes no sense for DVRs
- Most branches of wires already create a copy of the data. This depends on the function attached in the branch (e.g. "Array Size" does not create a copy of the data).
- Always copy forces the compiler to create a copy of the data on the wire for the following function(s). This disables compiler optimizations in many aspects.
When to use "Always Copy":
If you are not sure if compiler optimizations prevent data copies even if you are confident that you require the data redundantly.
Norbert
06-06-2013 03:40 AM
Hi Norbert
I was under impression that compiler will copies data only when you are modifying data in one or more branches.
06-06-2013 04:18 AM
...which is true for most branches.
You are correct that branches which do not modify the data will not create copies inherently (like "Array Size", "Search 1D Array", "Equal", ....).
But as soon as data is manipulated (like "Increment", "Replace Array Subset", ...) which are used in that different branches will create copies.
Norbert
06-06-2013 09:15 AM
I've only seen the Always Copy function used in very rare cases. And when it does it is to get around a bug in a version of LabVIEW as a work around. I have never seen this function used in everyday programming.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord