From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Performance when indexing 1D array from 2D array

Solved!
Go to solution

In the attached snippet, I am trying to store images from a camera in a pre-initialized array. The function GetImages16 is a commercial wrapper for a DLL that takes in a pointer to a 1D array and writes the camera image there. My array Images will need to store ~1500 frames of 128x128 pixel images, so I've allocated a 2D array of 16384x1500.

 

The problem I have is that the indexing of Images array slows down considerably as I increases the number of frames, and I can't keep up with my camera. Three things fix this code:

1. Decreasing the size of Images from 1500 frames to <400 frames or so.

2. Making Images a 1D array and passing it directly.

3. Moving the indexing code outside of the loop.

 

So, even though the location of the first frame of Images shouldn't be changing, it seems to take significantly longer (~5 ms) to perform the indexing of Images when the pre-initialized array gets big (>400 frames). This suggests I might not be managing memory very well, but I'm a relative LabVIEW noice in this area. I have tried indexing column instead of row and get the same performance.

 

Suggestions?

0 Kudos
Message 1 of 5
(2,402 Views)

Can you show more of your code than that image?

 

Don't use a local variable. The best (most memory-efficient) option is to store the array in a shift register around the while loop, but it would help to see what's happening inside the subVI. For optimal memory use the subVI should have both an array input and an array output.

 

Why is there no loop timer in your while loop? How fast does it need to run? It's rarely a good idea to have a loop running indefinitely without any timing, since it will consume as much processor time as available and prevent other tasks from running.

0 Kudos
Message 2 of 5
(2,385 Views)

Thank you, nathand. When I pipe in the Images array directly, with or without a shift register, it performs great. The reason I had made Images a local variable was that I want to perform analysis on it in another parallel UI-controlled event loop. What's the best way to make Images available to another loop?

 

More complete code is attached, if it helps. The loop pulling from the camera is bottom left, the initilization is far left, and the event loop is middle. The acquisition loop is currently timerless because there's a camera function that will put it to sleep in between acquisitions.

0 Kudos
Message 3 of 5
(2,369 Views)
Solution
Accepted by topic author sleachman

Maybe I'm just not seeing it, or maybe it's not visible in that image, but I don't see anywhere that you write to to the "Bead Images" local variable, so I can't see how it's helping you. Again, it would help to see the subVIs. Can you post a ZIP file containing all your VIs, instead of just images?

 

To share a large array between loops, the best option is an action engine VI that stores the large array in an uninitialized shift register. At a minimum it should have actions to initialize the array, store an image into the array, and retrieve an image. It might also have other processing options so you can operate directly on the array data.

0 Kudos
Message 4 of 5
(2,364 Views)

You're right, actually. I had assumed that because GetImages16 took in the pointer to the array and wrote in the same location that I could read from the local variable and would get the written data, but that doesn't seem to be the case.

 

Thanks, again. I'll study up on action engines.

0 Kudos
Message 5 of 5
(2,357 Views)