LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Avoid memory copies

Hi All, 

 

I am trying to avoid making multiple copies to Improve efficiency. Attached is the vi taken from a larger program. The idea here is to replace 2 D array(Image data) at each iteration, the vi attached shows the first 8 pages of the 3d array is being replaced. This number could change ,that is why I’m allocating 100 pages on the 3d constant. However, the performance of the vi seems to be dependent on the 3d array size which might suggest to me that I’m making data copies for each iteration. In theory, if what we are doing inside the for loop is just replacing the 2D array of 0 to 7 pages, the performance should be independent of the 3d array size? I have used the “show buffer allocation “ tool and there is not buffer allocated at the shift register. Does this mean that we are not making multiple copies for each iteration?

 

 

 

Please advice

Thanks

0 Kudos
Message 1 of 6
(2,337 Views)

The shift register does not make copies at the terminals.

Playing with your example code a bit, if I take your 3D array constant and replace it with an Init Array function then I can easily change the number of pages. However, the number of pages has no effect on the execution time. 10 pages to 310 pages all take approximately 700ms to execute your for loop, so I cannot reproduce the issue you are describing.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 6
(2,324 Views)

Another way for speeding up if you working with images you can use IMAQ Vision functions instead of arrays.

 

The following code which is functionally equivalent with yours will take less than 100 ms in comparison with your version which takes 670 ms on my PC:

 

imaq.png

Message 3 of 6
(2,317 Views)

A 3D array very quickly grows in size, you're not running out of memory and get swapping? That'd explain rapid speed degeneration over certain sizes.

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 6
(2,315 Views)

Yamaeda: The 3D array is not growing, only data replacement is occuring here.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 5 of 6
(2,313 Views)

Well, you array has 31M element, using 120+ MB of memory. This will not fit in the processor cache, so there is some penalty.

 

You have to be really careful with constant folding, because you are using diagram constants. If I disable debugging in your code, it executes in 0 ms because everything is folded. After replacing the constants with controls to avoid folding, it still executes 20x faster than with debugging enabled. A lot of the overhead seems to be in the debugging code.

 

(I would also wire the output to somewhere, else the compiler might eliminate the entire thing as part of dead code elimination.)

Message 6 of 6
(2,278 Views)