LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding DVRs

Solved!
Go to solution

LV2013, Win7

 

I'm an old hand at LabVIEW, but brand new to Data Value References (DVR), and I'm not understanding what I am seeing.

 

I have a class, that contains one I32, and has one method to increment and display that number.

My main program has what i think should be a SINGLE INSTANCE of that class.

 

Main can launch any number of "Child" VIs, each in separate windows.  The child VI is reentrant.

 

When I launch a child, I create a DVR to the one and only instance of the class, and off you go:

DVR Test Main.PNG

 

The child VI is set to OPEN FRONT PANEL WHEN CALLED.

 

It has a GO button, and when you click that, it dereferences the DVR, and calls the INCREMENT method on that class.

 

 

DVR Test Child.PNG

 

 The class method is simple: DVR Test Dialog.PNG

What I EXPECT to happen is that there is ONE and ONLY ONE instance of the class.

The children get a REFERENCE to that class, and operate on the REFERENCE.

So therefore, the I32 in that class would get incremented by a call from EITHER child.  And they both operate on the same instance of the same class.

 

BUT NO.

 

What ACTUALLY happens is that it appears there are TWO instances of the class.  Each child "owns" its own copy and they are independent.

 

 

The class method is NOT reentrant.

The class is set so that RESTRICT REFERENCES TO CLASS METHODS is OFF, so that I can create the reference at launch time (is that a problem?)

 

Here's a JING showing what happens: <http://www.screencast.com/t/2gN64oWF>

 

Attached is a project.

 

if I launch 3 or more instances, there are 3 or more different integers.

 

What's wrong with my thinking?  Why aren't the two children referring to the same instance of the class?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 32
(11,068 Views)
Solution
Accepted by topic author CoastalMaineBird

I might be wrong but I think the problem is you are making a new DVR for each child.  Each child has a reference to new data space.  What you should do is create the DVR once, and pass that same reference to each child not make a new DVR for each one.  Also don't forget to close that DVR (or DVRs) when you are done.

Message 2 of 32
(11,049 Views)

I'm not familiar with them either but I think you should probably use the in-place structure to operate on them.  Maybe?

 

Edit: Scratch that, you are using in-place. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 32
(11,029 Views)

Steve,

 

I took a quick look and found

Capture.png

You need to create 1 DVR and pass it to all Child.vi clones.

 

I know it seams counter-intuitive but you were operating on multiple DVRs to the same class So you got multiple data spaces (1 per DVR)


"Should be" isn't "Is" -Jay
Message 4 of 32
(11,023 Views)

OK, I -AM- closing the DVR (each child closes it when terminating - not shown)

 

And moving the CREATE DVR outside of the while loop does the trick.DVR Test Main 2.PNG

 

But that makes zero sense to me.

 

A reference to X is a reference to X isn't it?

 

Why does creating a new reference to X actually create a new INSTANCE of X?

 

Is that a special rule for classes, or does that apply to a boolean as well?

 

Is that why the "RESTRICT REFERENCE OF THIS CLASS to MEMBERS" is normally ON ?

(i turned it OFF here)

Maybe if I create the reference from INSIDE the class, it doesn't have this weird behavior?

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 32
(11,003 Views)

CoastalMaineBird wrote:

 

A reference to X is a reference to X isn't it?

 

Why does creating a new reference to X actually create a new INSTANCE of X?

 

Is that a special rule for classes, or does that apply to a boolean as well? 


Nope not special.  It is a bit hard to explain but it is like creating a new queue.  I am making a new reference to a new queue, it doesn't matter if I use Obtain Queue and use the same constant wired to each of them, it will make a new reference each time.  Same here.

0 Kudos
Message 6 of 32
(10,994 Views)

OK, if I turn the restriction back ON, and give the class a method that CREATES DVR to itself, then it still fails.

 

And it makes even less sense.  It's the same instance of the same class, so how does creating a second reference, create a second instance?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 32
(10,993 Views)

@CoastalMaineBird wrote:

OK, I -AM- closing the DVR (each child closes it when terminating - not shown)

 

And moving the CREATE DVR outside of the while loop does the trick.

 

But that makes zero sense to me.

 

A reference to X is a reference to X isn't it?

 

Why does creating a new reference to X actually create a new INSTANCE of X?

 

Is that a special rule for classes, or does that apply to a boolean as well?

 

Is that why the "RESTRICT REFERENCE OF THIS CLASS to MEMBERS" is normally ON ?

(i turned it OFF here)

Maybe if I create the reference from INSIDE the class, it doesn't have this weird behavior?

 



My understanding.

Yes, that is exactly why you are "Being Bad" by allowing anybody to create a DVR to the private data.  

 

The DVR is a "Location in memory where data is held" two DVRs can't point to the same location they however can point to the same data type.  And you certainly proved that creating multiple DVRs to the same class creates multiple instances of the class data. 

 

So, I would recommend Turning "Restrict...." back on and only allow a class member to create the DVR to pass to child.vi clones.

 

 

EDIT: Keeping up with this is funky.

 

Your DVR Create method should only create a new DVR if the current DVR is invalid otherwise pass the valid DVR (Noting that if a DVR becomes invalid those vi's using the invalid DVR should fail)


"Should be" isn't "Is" -Jay
Message 8 of 32
(10,990 Views)

Remember a class is just a cluster (sorta) so if you passed the class into the VI that then made the DVR it doesn't matter, they are all still getting some cluster data, and turning it into a new reference to a new set of memory space.  As Jeff said you want to pass in the reference (or a class with a reference already in it) so creating the reference is centralized.

 

What ever you wire into a create DVR is like splitting a wire and it will make a new copy of that data in memory.  The only difference is now you can split that DVR wire (or pass it into multiple VIs) and it won't make a new copy of the data in the DVR, but may make a new copy of the refnum which isn't that big of a deal since it is just a pointer essentially, and not the actual data.

Message 9 of 32
(10,982 Views)

@Hooovahh wrote:

 I am making a new reference to a new queue, it doesn't matter if I use Obtain Queue and use the same constant wired to each of them, it will make a new reference each time.  Same here.

But it's a reference to the SAME QUEUE.

If I use reference A to enqueue something, I know that I can use reference B to dequeue that same something.

 

What I see here is it's creating a new instance.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 32
(10,978 Views)