LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I correctly preallocate an array to reduce memory?

Hi all,

 

I have a very large 2D data set that I am trying to load into LabVIEW... The file is in tdms format... Previously, I was reading the data in with chunks of 20,000 x 7 elements and was building an array each iteration until the EOF in an attempt to reduce the memory hit... However, this really this did not work as I was using less memory when reading the whole file into to memory as once... So the using the "build array" vi is very inefficient int terms of memory usage (as all the doc say)...

 

So, instead of building an array I would like the preallocate a memory to an array of filled with "0's" then replace an array subset on each iteration with the 20,000 x 7 element chunk... This sounds simple enough, but I cannot get this to work...

 

Could some please post some example code for this?

 

Thanks,

Jack

0 Kudos
Message 1 of 4
(2,895 Views)

The load once option should only create a single array to hold the data, so I don't think you can do better than that. If you want the whole thing to end up in memory, it takes what it takes. If you still want to try preallocation, you'll ned to use 'initialise array' and 'replace array subset'.

0 Kudos
Message 2 of 4
(2,881 Views)
Hi ToeCutter, Yes, I did that... the intialisation was outside the while loop... When I ran the vi, a big memory hit was taken (preallocation), but when reading the data in chunks and 'replacing array subset' memory kept increasing with each loop iteration? Jack
0 Kudos
Message 3 of 4
(2,834 Views)

Please post a code snippet.

0 Kudos
Message 4 of 4
(2,816 Views)