07-17-2012 03:15 PM
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.
07-18-2012 06:05 AM
@Ben wrote:
When in C point. When in LV, wire.
Another LabVIEW proverb. Thanks, Ben. 🙂
10-22-2012 07:05 PM
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???
10-22-2012 08:35 PM
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.
10-22-2012 09:12 PM
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.
10-23-2012 07:47 AM
@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
10-25-2012 08:53 AM
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.