LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient Memory Use

Apologies in advance for the image quality. I wanted to ask what is the correct way to execute the code. Thank you!

0 Kudos
Message 1 of 4
(382 Views)

21cbbb8d-fa2e-4b2b-a292-4f5b77ae9fdd

Both are OK.

 

In this situation, I'd prefer converting in the loop (bottom), because the array you're building is smaller:

top: Building a 8000 byte array, converting it to 4000 byte.

bottom: Converting 8 bytes to 4, building a 4000 byte array.

 

So, the bottom one will be easier on memory allocation.

 

I doubt you'll notice the difference in practice (although you can benchmark the two).

Message 2 of 4
(369 Views)

wiebe@CARYA wrote:

21cbbb8d-fa2e-4b2b-a292-4f5b77ae9fdd

Both are OK.

 

In this situation, I'd prefer converting in the loop (bottom), because the array you're building is smaller:

top: Building a 8000 byte array, converting it to 4000 byte.

bottom: Converting 8 bytes to 4, building a 4000 byte array.

 

So, the bottom one will be easier on memory allocation.

 

I doubt you'll notice the difference in practice (although you can benchmark the two).


There are Tools that will help!  Right in the Tools Menu!

 

You can:

  • Show buffer allocations and see that the Add happens inplace
  • Use to VI profile tool to show runtime memory cost.

By the way, that For Loop could be "Parallelized" even though you might get a warning.   The PRNG will always execute the right number of times so you'll always get the same values given the same initial seed value but, the iterations may not be sequential changing the order or the values in the array.

 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 4
(318 Views)

@maxnoder1995 wrote:

Apologies in advance for the image quality. I wanted to ask what is the correct way to execute the code. Thank you!

21cbbb8d-fa2e-4b2b-a292-4f5b77ae9fdd


Most likely the compiler will rearrange the code for most optimal behavior use and it really does not matter once debugging is disabled. (when debugging is enabled, we need to be able to probe the array after the loop and there will be a slight difference.).

 

Still 1k points is trivial. Start worrying once you deal with a few orders of magnitude more points. Note that you also could do the addition inside the loop.

 

altenbach_0-1720448730111.png

 

 

(I am worried that if you even have problems taking screenshots or properly cropping pictures, you might not be very computer savvy and you are going down the rabbit hole trying to worry about things that don't really matter.. Focus on getting the right result with scalable and easy to read code the rest does not matter here)

 

I am also pretty sure that parallelizing the FOR loop would actually slow you down. Only do that if the code inside the loop is heavy.

Don't forget that the array indicator also has a 4k transfer buffer.

 

0 Kudos
Message 4 of 4
(296 Views)