LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

it is the reason of memory?

There is an array in my program. It can run slowly when it has 2M I32.But when it increase to 4M,it can't bare.
I have 512M memory in my computer. Is it the reason of my memory is too small?
Thanks.
0 Kudos
Message 1 of 15
(3,246 Views)

Well, any computer should be able to handle an 4M array of I32 (~16MB).

Look at your buffer allocations to see how many copies of the array are in memory. Do some profiling. What is the memory usage of the VI during run? Remember that e.g. local variables create data copies.

Some more questions:

  • Is the array of fixed size or are you continuously growing it in a loop during run?
  • Are you constantly resizing the array (insert into array, delete from array, etc).
  • Is the array possibly in an uninitialized shift register?
  • Are you constantly sending the huge array to e.g. a graph indicator?

Easiest would be if you could attach your code. Maybe we can point out some obvious bottlenecks. 😄

Message 2 of 15
(3,238 Views)
I have found that the detail you ask me to pay attention is all in my program. This is my first time to use LabVIEW. I don't know how to save memory. I am glad to share the file to let you help me. Thank you.
The "rar" file is not allowed, so I have changed it to "vi".After you download it, change the file to "rar" and unpack it before open it.
Thank you.
0 Kudos
Message 3 of 15
(3,234 Views)
The main file is "Untitled.vi" in MP421
0 Kudos
Message 4 of 15
(3,234 Views)
Hi Hugo,

well, your vi is LabView7.1 and not 7.0... And you can create libraries (llb's) by using 'File->Save with options'. So you don't need RAR and renaming.

Some comments on your vi:
1) Your vi is way to big to fit a screen. How can you have an overlook of what you are doing?
2) You use local variables much too often. Try to use wires instead! By using locals you risk race conditions (there are some in your code)!
3) You use many 'simple' controls/indicators. Try to group those data. Example: your Lglobal.vi contains 16 times Unit,Color;Min and max. Make a cluster of those and after that an array of cluster!
4) The same applies to your untitled.vi: Many single controls/indicators where (array of) clusters will do/help!
5) All your subVi have the same icon. How can you work this way?

6) For your memory problem: Please use Tools->advanced->Show buffer allocations. Every black dot means 'new memory allocation'! Especially when handling arrays at those dots this can lead to problems.

I cleaned up the case at the bottom of your main vi (just a little bit). The main problem stays: continously memory gets allocated by the 'build array' function!

Try to enhance your programming skills. RTFM and (at least) the development guidelines. There are also many threads and even application notes on memory consumption and effective programming!


Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 15
(3,213 Views)
Hi GerdW,
Thank you very much for your reply. I have found that there are so many kind person in the forum of NI. Surely you are the excellent one.
I have read the vi you have cleaned up. That is the very one I need. Thank you very much. I want to give you more point, but the max is 5.:(
I am curiouse that you are the staff of NI or the fan of LV.:)
 
Good Luck!
Thank you!
 
Hugo
0 Kudos
Message 6 of 15
(3,195 Views)

Hi Hugo,

Thanks for the great comments for GerdW!

The gold bars under Gerd's name indicates "non-NI".

If you have time, you can review this list of Gred's answers and and award stars for some other answer that may have gone over-looked.

http://forums.ni.com/ni/tracker?user.id=16916

Ben

Go Gold Team!

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 15
(3,179 Views)
Gerd is absolutely right!
 
You seem to be using tons of hidden controls for the sole purpose of creating local variables. They all can be completely eliminated!
 
Last night while watching news, I made a quick attempt to correct some code flaws (see attached). Look for the green comments everywhere.
 
To the performance issue:
The only place you use an array is in the small while loop. Here you need to initialize the full array once (the size is exaclty known from the ring!), then replace with data as you go. I am not sure if your subVI always produces the same amount of data with each shot. If so, you can use a FOR loop because the iterations are known.
 
I did not finish all the cases, so just repeat what I have started. Since all properties are written only if relevant inputs change, some might need to get initialized at program start.
 
modify as needed.
 

Message Edited by altenbach on 07-27-2006 08:54 AM

Download All
Message 8 of 15
(3,161 Views)
I have tried the Gerd's method. That is to use the shift register in the while loop.
And to use the "build array" not use the "replace array".
When the array is chosen to 4M. The computer also makes a mistake.
Which is the better way? build array or replace array.
I don't know the mount of data with each shot. so for example, I decide to get 1k data, and I have initialized an 1k array, when I have gotten 999 data. next the length of array is not 1, such as 5,can the "replace array" work properly? Make the length of array to 1004?
Thank you!
 

Message Edited by Nick C on 07-28-2006 12:36 PM

0 Kudos
Message 9 of 15
(3,130 Views)


@hugoliang wrote:
And to use the "build array" not use the "replace array".
When the array is chosen to 4M. The computer also makes a mistake.
Which is the better way? build array or replace array.

"Replace array subset"  is ALWAYS better. When you use built array in a loop, you are changing the size of the array with each loop iteration, causing expensive memory reallocation operations. In contrast, this needs to be done only once If you initialize a full-size array at the beginning of the loop. For large arrays and large N, the performance difference will be enourmous. Trust me.

The computer does not make mistakes, there must be a mistake in your code. Can you explain in more detail what kind of "mistake" you're seeing?


@hugoliang wrote:
I don't know the mount of data with each shot. so for example, I decide to get 1k data, and I have initialized an 1k array, when I have gotten 999 data. next the length of array is not 1, such as 5,can the "replace array" work properly? Make the length of array to 1004?
Thank you!


Well, you need to initialize the array to a reasonable upper limit, for example size 1010 in the above example. After the loop, you know exacly how much data you have and you can trim the array to the exact size. This is still much more efficient.

Message 10 of 15
(3,110 Views)