LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

In-Place Element Structures, References and Pointers, Compiler Optimization, and General Stupidity

Along with what has already been said I did want to nitpick on one thing you mentioned. You tried saying that passing a reference to a control of an array would not allow you to get the size of the array without first getting a copy of an array. This is true but it is also true in C/C++. If you pass a pointer to the array you cannot determine the size of the array. The only thing you may know is the maximum size based on some #DEFINE in a header file.

 

But as others have already stated you are comparing apples to oranges. The underlying programming paradigm is very different between the languages and you really need to understand which one you are working in to create decent code.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 11 of 17
(1,852 Views)

@Ben wrote:

 

When in C point. When in LV, wire.

 


Another LabVIEW proverb.  Thanks, Ben.  🙂

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 12 of 17
(1,821 Views)

So perhaps this is the reason why you guys and I don't seem to be clicking. I understand the responses I've received. But when you write a program, you have controls (the onscreen UI-related controls you guys speak of), but you ALSO have data structures that do NOT have to be represented as controls; they are used BY THE PROGRAM and NOT as part of the user interface.

 

So THOSE are the items I wanna pass pointers to.

 

For instance, I read in a (large) table that controls a lot of what my program does; different parts of the program need access to different parts of the table. The user NEVER SEES IT on the UI. I don't want to make it a global;I don't want to keep making local copies of this GIANT table every time I need to pass it to a SubVI or use the Value property to get at it.

 

So how do I implement it??? The only thing I've seen is as a control; basically in my case an arrray of clusters, each cluster being a record in the table (they all have the same format). It needs to be quickly accessed (RAM resident) and, in C, to make it efficient (since it's read only) it should be passed as a pointer. What do I do in LabVIEW???

0 Kudos
Message 13 of 17
(1,737 Views)

Put the data in shift register.  That shift register might be inside a functional global variable or simply around the main loop of your program, depending on how you need to access it.  If it's read-only, search this forum for WORM (Write-Once Read-Many) - there are some example implementations and it sounds like that's roughly what you want.

 

LabVIEW generally uses the Copy-On-Write approach.  Say you store your data in a functional global variable, and you put that VI all over your code to get access to the data.  You're not making a copy if you simply read it.  You only get a copy when you modify that data, and even then you may get a copy of only the modified elements and not the entire array.

 

Does that help?  It sounds like you're assuming that LabVIEW makes copies where it does not.  Branching a wire or returning data from a subVI does not imply a data copy.

0 Kudos
Message 14 of 17
(1,730 Views)

What's wrong with using a global variable.  This is a perfect instance for a global variable.  You are setting up a table once and reading it whenever you need.  Just use a global variable and you are fine.

Here's a good explaination from Darren's blog.


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
Message 15 of 17
(1,725 Views)

@sbus wrote:

So perhaps this is the reason why you guys and I don't seem to be clicking. I understand the responses I've received. But when you write a program, you have controls (the onscreen UI-related controls you guys speak of), but you ALSO have data structures that do NOT have to be represented as controls; they are used BY THE PROGRAM and NOT as part of the user interface.

 

So THOSE are the items I wanna pass pointers to.

 

For instance, I read in a (large) table that controls a lot of what my program does; different parts of the program need access to different parts of the table. The user NEVER SEES IT on the UI. I don't want to make it a global;I don't want to keep making local copies of this GIANT table every time I need to pass it to a SubVI or use the Value property to get at it.

 

So how do I implement it??? The only thing I've seen is as a control; basically in my case an arrray of clusters, each cluster being a record in the table (they all have the same format). It needs to be quickly accessed (RAM resident) and, in C, to make it efficient (since it's read only) it should be passed as a pointer. What do I do in LabVIEW???



Without getting exotic you have two choices (I rule out globals due to data copies).

 

Action Engines or DVRs.

 

The first can be viewed as implicit and the latter as as an explicit pointers.

 

Action Engines (see the link I included) store the data in a Shift Register which maps to a Static Local in C in that the data persists in memory at a sinlge location but is only accesable using the function that has the Static Local (again see that linked Nugget).

 

DVR's on the other hand do provide a pointer that you can pass around to allow access to the shared data.

 

So do you wnat your data on the outside or the inside, you choose.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 16 of 17
(1,706 Views)

Hi sbus,

Have you had much multi-threading experience?  Or mostly single-threaded C?  There are issues with by-reference access to data in a multi-threaded system that need to be considered.  That's why LabVIEW has no naked, unprotected pointers (and you shouldn't be using such things in multi-threaded C either).  The LabVIEW techniques most similar to what you want to do are (as others have explained):

 

-- Pass the data through subVIs by-value, and back through loops in a shift register.  This effectively single-threads the data (and under the hood the compiler uses pointers; no copies).

 

-- Use a DVR with it's inherent locking mechanism to "serialize" access to the data.

 

-- Use "Action Engines" or similar techniques to get similar serialization.

 

 

Message 17 of 17
(1,660 Views)