From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

G#

cancel
Showing results for 
Search instead for 
Did you mean: 

By reference vs. By value

I used Sybio GOOP for few projects and quite aware of few things in it.  Out of those experience, I'm going to give some presentation (@CLA Summit India) on my experience with GOOP and how it actually leverages the LVOOP.  Though I have used it widely, I'm not basically from computer science stream and had no good idea about OOP itself.  Now I have fair idea about OOP by going through some books.  I am looking back at GOOP now and have lot of questions on my way.

  • Why one should use by-reference over by-value.  What are the advantages of by-reference.  What can't be done with by-value which is filled by by-reference model.
    • I got to know that it gives control over construction or destruction of the objects.  I uderstand from googling that widely other languages (like C# C++ etc) use by-references model, I assumed that it's common design pattern or programming paradigm which would be advantageous.  However, I have no clear answer for this.

I have posted this question in GOOP community and I'm waiting for the response.  Meanwhile, I thought of posting it here to get some answers. 

Thanks,

Ajay.

--
Ajay MV


0 Kudos
Message 1 of 4
(7,086 Views)

Hi,

One simple reason - if you fork you wire in by-value based OO, you actually clone the object. You don't do this in by-reference. This is a hugh problem using by-value when you e.g. have two parallell loops and want to work on the same object in both loops. When using by-value classes you usually end up putting a queue or something like that in your class private data and then actually converting to a by-reference class even if it looks "by-value".

Mattias

Message 2 of 4
(6,347 Views)

Mattias_Ericsson,

Thanks for the reply.  Is there any other vital reason when people goes for by-reference?   I always thought if I need a singleton-class, I can have the LVOOP object in an FGV or global and share it between the loops.

There is some more reply from the other thread

https://decibel.ni.com/content/message/138128#138128

-Ajay

--
Ajay MV


0 Kudos
Message 3 of 4
(6,347 Views)

Yes, you can easily solve it that way. In G# you can create a singleton class in which case any reference will grab the same instance.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 4
(6,347 Views)