LeifS Posted April 13, 2010 Report Share Posted April 13, 2010 I recently tried to use DVR's with LVOOP, but I evidently use it the wrong way, since it doesn't work as I want. But the question is: Why can't I use DVR's this way? (see this simple project: ClassTest.zip) Quote Link to comment
K-node Posted April 13, 2010 Report Share Posted April 13, 2010 I recently tried to use DVR's with LVOOP, but I evidently use it the wrong way, since it doesn't work as I want. But the question is: Why can't I use DVR's this way? (see this simple project: ClassTest.zip) Lief, My quick take... In the getClass2Reference.vi method, you are returning a reference to a copy of the Class2 instance that Class1 maintains. For simplicity, I always assume that when a wire is branched, the data is copied. So in this case the copy does not share the same memory for Class2's member variables (aka private data), String1 and String2. If you had a setClass2Reference.vi method which accepted a reference and used the dereference value to set Class1's member variable it would work. That would be kind of a silly solution - not sure what value the DVR brought you. Some of us have made the member variables of a class a DVR. So, any copies from a branched wire will still point to the same data. Care should be taken with this approach and you will find lots of discussion on this topic in this forum. Others make the class itself a DVR. Again, branches would have identical DVRs so any dereference would get you to the same data. Hope this helps. -kg Quote Link to comment
LeifS Posted April 13, 2010 Author Report Share Posted April 13, 2010 In the getClass2Reference.vi method, you are returning a reference to a copy of the Class2 instance that Class1 maintains. For simplicity, I always assume that when a wire is branched, the data is copied. So in this case the copy does not share the same memory for Class2's member variables (aka private data), String1 and String2. OK, so the InPlace-Unbundle doesn't help at all to prevent data copying of the class. Correct? Quote Link to comment
Aristos Queue Posted April 13, 2010 Report Share Posted April 13, 2010 OK, so the InPlace-Unbundle doesn't help at all to prevent data copying of the class. Correct? Correct. The inplace structure just says that the data coming into the left edge of the structure will be the same memory location as the data going out the right edge of the structure. Between the left edge and the right edge, if you fork the wire along the way, that other branch is a separate object. Under the hood LV might avoid actually making the copy if it can to save memory, but it will behave as if it is a separate object, and as soon as that branched wire leaves the structure or is connected to a node that modifies the value, or any operation like that, then a copy is definitely made. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.