LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Store the Data

Instead of using the "build Array", restructure your code to use a "Replace Array Subset". You will have to track the insertion point in another shift register.

Explanation:

When the size of an array is increased (like when you are doing your build array), LV will first check to enusre there is enough memory allocated to store the update array.

If NOT,
LV will allocate additional memory (i.e. waste a lot of time) before allowing the operation to take place.

By using the "Replace array",
You can pre-allocate your memory buffer the first time the buffer is used. This could happen in your "reset" case. Just use the "Inititalize array" function with more memory than you plan to use. This moves all of the "memory allocati
on" interuptions "up front" before the real code starts running. You will also have to reset your insertion pointer at this time.

The "RTeplace array subset" operates "in-place". This means that ONLY the new values you are adding to the array are actually moved around. The rest of the array stays right were it was.

NOTE:
Your image should that you are still reading from globals. These reads will skew your benchmarks.

Use your "new" global every place you would have used the globals.

I have written some fast code. I did it using LV2 globals.

The only time I ever use "normal globals" is when I am working on someone elses code, it is too difficult to replace all of the globals, AND there are no race conditions.

Trying to help,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 11 of 23
(1,777 Views)
Please look at Altenbach's example.

He knows what he is talking about, and he is giving good advice.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 12 of 23
(1,777 Views)
jonni wrote:
> I tried several experiments, I run my application 30
> seconds: (Each cycle increases array)
>
> 1. No storing the data: 182000 cycles, 6100 commands/sec
> 2. Shift register (see the picture): 22000 /735 3. my
> old method using only global variables: 17890 /596
>
> So........ The main amount of time takes the actual
> adding element to array and NOT the use of global
> variables 😞

I think the problem is that you just don't get it. It's
really not your fault :-). Sometimes it's hard to grasp the
concept of LV2 style globals and how they can be used in a
given application. The image you've attached is a
contradiction. You are using regular globals to feed LV2
style globals. Here is a link with
more information on these
special globals and how they can be used:

http://forums.lavausergroup.org/index.php?showtopic=273

There you will find a full working example of how to pass
data around your application using LV2 Globals. Note that
the example uses a build array function but it can easily be
replaced with a "replace array element" function.

--
Michael Aivaliotis
http://mmwis.com
http://forums.lavausergroup.org
http://niweekblog.com


Michael Aivaliotis
VI Shots LLC
0 Kudos
Message 13 of 23
(1,616 Views)
I pre-initialized array and then used "Replace Array Subset".
With this arrangement I have achieved the speed same as when I do not store the data :).
It looks like my problem is solved.

Many thanks for everyone. It was very useful.
0 Kudos
Message 14 of 23
(1,779 Views)
Thanks for your example BUT it wasn't really about my problem. As was said before the main problem was how LV adds elements to array. The problem is solved if I pre-initialized array and then just insert in it.
0 Kudos
Message 15 of 23
(1,616 Views)
Cool!

Job done, NEXT.

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 23
(1,781 Views)
It is done but not in total:(
Now I can easily store my data BUT I have different problem 🙂
I'm trying to read the data from my "memory" (Attached picture).
It slows down speed by factor of 5+. Are any better ways to obtain data from storage?

Thanks
0 Kudos
Message 17 of 23
(1,618 Views)
Well, it seems you are still using globals, at least for the rows. Why not use wires and terminals?

It is very difficult to make sense out of a code image, couldn't you attach a sample VI?

What are we looking at here? Is this now part of a LV2 style global or just a diagram section of the main VI?

What is in the other case of the case structure? The boolean is called "Add/read?" but we are looking at the "false" case, so why do we "read" here at all? Do you really need to read the full array subset whenever a column is added? (This creates a partial copy of the big array which again can be huge). Why don't you create a third case called "read"? How is the shift register i
nitialized? In the "false" case?

Probably you need more than two states, e.g.:
(1) "Add": adds a row
(2) "read": reads out currently filled subset (to be used rarely).
(3) "Initialize"
etc.

Could you reduce your project to the essential parts and post it as an llb? Too many things get lost in translation by using only words and pictures.
Message 18 of 23
(1,618 Views)
I disagree! 😉

A big part of your problem is the use of global variables. A LV2 style global is what you need instead to hold your array.
Message 19 of 23
(1,618 Views)
I have attached a LV2 global style VI to store a large array efficiently. Notice that the whole array exists only in the shift register of the while loop. You invoke the VI every time you need to access the array. The best is not to use resizing functions so you initialize the array to a fixed size and then replace elements/subsets. This can also be done for a 2D array.


LabVIEW, C'est LabVIEW

Message 20 of 23
(1,618 Views)