LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP with DVR - Best Practices and Caveats


@AYanez wrote:

Hi Wiebe, I hope not bother you, I would like to know your tips about how you will face my problem with a by value approach,  getting both sides of the coin would be a great learning for me. 


That's no bother...

 

I've just briefly looked at the code, and it is simplified enough for me to actually look into it a bit. Is this representative of your needs? E.g. if this would work by wire, would that work in your real situation?

 

Not sure if\when I get to it, seems like a fun Friday afternoon project. Not sure if I can make it this Friday, I have a few things that I should work on (and I'm actually getting paid for).

0 Kudos
Message 31 of 36
(871 Views)

Hi Wiebe, so after a while and thinking a lot about it, evaluation of performance and usage cases I change the approach and stick with by value for this application although recently I used a DVR Singleton for other task, I learned much with this discussion 🙂

 

My new strategy consists in move the data to disk in a new efficient format, of this way I dont need to store the data in RAM, and I can retrieve this in different points of the program when be needed.

 

But I am curious about how do you handle classes with refnums. Part of my new strategy involves a class with file refnums, I know refnums are by reference and I am storing a refnum control inside private data of a file class, everything works ok but the by reference behavior is not explicit due the wire appearance (By value object for now) my question here is: Is ok to include file refnums inside by value classes? My questions comes from the fact that I can convert this to a by reference class but I am using this class in another (Composition) so the composed class will inherit by reference and I will have to do the same (By Reference conversion) and I will return to the same situation.

 

Thanks for your attention, I have enjoyed to learn new concepts in the forum from all members.

0 Kudos
Message 32 of 36
(837 Views)

@AYanez wrote: Is ok to include file refnums inside by value classes?

Nothing wrong with that.  I recommend having a "Close" method to call when you are done with said object to allow it to close the file reference.  I actually recommend that with any object that even might have a reference in it.  Definitely should have a close method for anything related to hardware (reset, put into a known safe state, etc).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 33 of 36
(830 Views)

@crossrulz wrote:

@AYanez wrote: Is ok to include file refnums inside by value classes?

Nothing wrong with that.  I recommend having a "Close" method to call when you are done with said object to allow it to close the file reference.  I actually recommend that with any object that even might have a reference in it.  Definitely should have a close method for anything related to hardware (reset, put into a known safe state, etc).


Agreed. Nothing wrong with references inside 'by value' classes in general. Where you will get yourself into an ugly code situation is when you use that class in your application knowing it has a by reference component internally, if that is not an explicit component of the class. The internals of that class are just that - internals. If the public API doesnt make it clear that the class is to be used in by reference way, you shouldn't use it that way. 

0 Kudos
Message 34 of 36
(825 Views)

@AYanez wrote:

But I am curious about how do you handle classes with refnums. Part of my new strategy involves a class with file refnums, I know refnums are by reference and I am storing a refnum control inside private data of a file class, everything works ok but the by reference behavior is not explicit due the wire appearance (By value object for now) my question here is: Is ok to include file refnums inside by value classes? My questions comes from the fact that I can convert this to a by reference class but I am using this class in another (Composition) so the composed class will inherit by reference and I will have to do the same (By Reference conversion) and I will return to the same situation.


It all comes down to expectations. Or in fancy words, the contract you have with the class.

 

As long as it's clear to users (you, future you, others) of the class, that the class is by wire, by reference or contains references, you can do pretty much what you want. Even if it's not clear you can do pretty much what you want of course, but things might get messy.

 

Every LV programmer knows files work by reference. So I'd expect a class handling files to contain a references. How would by wire file handling even work? I'm sure it's possible, but would it be practical?

 

You can (and should) be pragmatic. I thing a lot of programmers choose by reference classes, as a pragmatic solution. Ironically, I use by wire classes and avoid by reference classes for the same reason. It comes down to your background, experience, environment, etc.. This holds even for using OO at all. Try introducing OO in a team (or project) that doesn't use it. Or vice versa...

0 Kudos
Message 35 of 36
(805 Views)

@AYanez wrote:

 

But I am curious about how do you handle classes with refnums. Part of my new strategy involves a class with file refnums, I know refnums are by reference and I am storing a refnum control inside private data of a file class, everything works ok but the by reference behavior is not explicit due the wire appearance (By value object for now) my question here is: Is ok to include file refnums inside by value classes? My questions comes from the fact that I can convert this to a by reference class but I am using this class in another (Composition) so the composed class will inherit by reference and I will have to do the same (By Reference conversion) and I will return to the same situation.

 


File refnums work well, as long as you don't try to store and reuse them between runs, but that is true for all references. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 36 of 36
(797 Views)