I hope you're all doing well and getting ready for the Holidays.
I was doing a peer review yesterday of one of our classes and found that a developer was designing the class methods like this:
This class is a very specific implementation and will not use inheritance for other classes in the project (as far as I know). My suggestions for this method (and for the rest of them) was to get rid of the DVR and have the I/O of the object for future inheritance:
So my main questions are:
1. Do you see any advantage of using a DVRs to access the properties of the class?
2. Assuming several processes call this method, does the application has a better memory usage with this approach specially with large amount of data? (LabVIEW will use a single reference to the class and will not have to create several object instances).
Correct me if I'm wrong but personally I would stick with the 2nd option because it provides better scalability but I would like to hear your thoughts on this.
Hope to see you in our next User Group Meeting.
Happy Holidays to everyone!
Solved! Go to Solution.
Do you want the class to be by value or to be by reference? Here is an example.
What is in the values of String 2 and String after running this VI? Well you can't really know what is happening in these VIs, but one might think the String 2 has abcd, and String has 1234, and this would be true if the class is by value like your solution. However if this is by reference then there are race conditions happening and the String 2 could be abcd, or 1234, and String could also be abcd or 1234. In some systems a by reference design is useful, and in some systems a by value one is useful. I typically use by value things for simplicity, and I use them for any values set in some kind of INIT that is meant to be a write once read many. And I typically use references for things that might change during a run. Here is another example:
What is the value returned into String? Well if the class is reference based then it will be whatever was last written in the upper loop. But if it is reference based it won't change.
Thanks for the clarification Brian.
I see what you're saying. Would you then agree that using a By Reference approach would be a better and more efficient solution for handling BIG amount of data in the class?
Would you then agree that using a By Reference approach would be a better and more efficient solution for handling BIG amount of data in the class?
Probably, but to be honest the compiler gets smarter with every release, and even though you are dealing with large amounts of data in what is basically a cluster, it is pretty good about not making copies of data in memory unless it needs to. The branch in that wire will invoke a copy (of some kind) since both wires need to operate on the data. Someone at R&D would have a better explanation about how much is copied, or how much is reused if parts of the cluster aren't modified. But in the worst case of a branch where all data needs to be copied, then you are right that copying just the reference to the data, instead of the data, would be better. In the way most class based APIs are used, with train tracks of classes and errors, you are serializing your operations, and probably aren't invoking memory copies.