LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/15/2009) - Always Copy

Highlighted

I wish I had more to say about today's function, "Always Copy", but to be honest it has had me a little puzzled since I first saw it.  The help was not-so-helpful in this case.  The idea is simple enough, copy the input to a new memory location.  I have had plenty of block diagrams light up like Christmas trees when I show buffer allocations so making copies has never been a problem, yet I know it is there for a reason.  The LV compiler seems to do remarkably well handling memory issues, and when in doubt tries to err on the side of extra copies.  Perhaps there are a few situations where things go wrong in the other direction and this function will help.  Or, maybe since we have been given more power to muck around with the allocation process, this is now required to restore order.

 

I'd really like to see an example where this function is used "naturally", ie. not to overcome a compiler glitch.  Of course, if you have seen a glitch that is fixed by this, that is also good to know.

 

VIOTD groundrules here

0 Kudos
Message 1 of 10
(2,195 Views)
Highlighted

Darin.K wrote:

 

I'd really like to see an example where this function is used "naturally"


I don't think there is one. The primitive is explicitly there to help you control how the compiler allocates memory.

 

If you search the LAVA forums, you should be able to find one of AQ's threads where he posts an implementation of a map which relied on this primitive - I believe it was used to make sure a new buffer is always created, so that the old one is guaranteed to stay in place, but I don't remember the details.


___________________
Try to take over the world!
Message 2 of 10
(2,182 Views)
Highlighted

Darin.K wrote: Of course, if you have seen a glitch that is fixed by this, that is also good to know.

 


There was a bug in LV 8.5 which could be solved by using the "Always Copy" function. See this thread. I don't have a use case other than overcoming compiler glitches, either.

 

Message Edited by dan_u on 10-15-2009 04:45 PM
Message 3 of 10
(2,177 Views)
Highlighted

Darin.K wrote:

I wish I had more to say about today's function, "Always Copy", ...

... 

I'd really like to see an example where this function is used "naturally", ie. not to overcome a compiler glitch.  Of course, if you have seen a glitch that is fixed by this, that is also good to know.

 


Great function for Bug fixes in LabVIEW!

 

Refer, for example, to the following threads:

 

Bug in cluster to array in for loop with non-indexed output

 

Unxepected behaviour with clusters inside of while loop with shift register

 

With best regards, 

 

Andrey.

Message 4 of 10
(2,171 Views)
Highlighted

Andrey Dmitriev wrote:

Great function for Bug fixes in LabVIEW!

 



Probably this was the purpose of this function Smiley Wink

It's great that the compiler tries to optimize (reuse) memory as much as possible, so there might be cases where it does it's job a bit overzealous and reuses memory where it shouldn't. Then this function comes in handy.

 

Message 5 of 10
(2,167 Views)
Highlighted

If you play with ddl's and pointers, this might be useful in some situations. But I havn't run into this yet in the real world.

Also I guess that when you want to get the best performance out of an critical algorythm, it might be useful to explictly copy the data of one branch of the wire and reuse the other branch.

I would generally say, that it needs to be used together with InPlace, Reference and that sort of advanced functions.

 

Felix

Message 6 of 10
(2,156 Views)
Highlighted

Also, here is a link to another thread where this Always Copy Vi fixed a bug in LV 8.6.1

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=386839#M386839

 

Edit*  I didn't see this link listed above.


I have always wondered about this fuction also.  I am just now getting more involved with using the in-place functions.

Message Edited by monzue on 10-15-2009 11:14 AM
Ben Yeske
0 Kudos
Message 7 of 10
(2,116 Views)
Highlighted

Aside from bug fixes...

 

I have not used it explictly in code development yet, but I beleve it can shine when doing heavy number crunching on a data set with multiple processesors. Here is the scenario where it could be used.

 

Suppose that memory is not an issue.

If we have a data set that is looked at by a bunch of number crunching routines that does not modify the data AND there is one that does update the data.

If we write code that presents the same wire to all of the sub-VI (with terminals on the icon connector wired thru) that crunch the data including teh one that changes the data...

 

LV can do allof the work in-place by controlling the execution order. By scheduling all of the "look only" code to run first and then allow the VI that modifies the buffer to run, everything can be done in place. But to pull this off, LV had to force the "lookers" to run first and THEN let the poking code to run.

 

If we use the "always copy" to feed the wires of the sub-VI's, LV can allow all of the number-crunching code to run in parallel on multiple cores.

 

Now before you reply saying the above is a convuluted example, let me ask "Did you really expect a simple use-case for a function that conteracts in-placeness?

 

Your thoughts?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 10
(2,061 Views)
Highlighted

F. Schubert wrote:

...to get the best performance out of an critical algorythm, it might be useful to explictly copy the data of one branch of the wire and reuse the other branch.

 


The ideas of Felix and Ben are kind of similar. This definitely makes sense. If you have two branches you can control which one creates a copy. Good point.

 

 

 

Message 9 of 10
(2,046 Views)
Highlighted
I knew it would be a tool for the power users since the rest of us spend our time fighting against making copies.  I also like its bug-fighting powers.  Most times when we come across a bug, the workaround is very complex because the compiler is going to do what it does and there is usually nothing we can do about it.  Here we can give it a little kick in the pants now and then.
Message 10 of 10
(2,038 Views)