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: 

Memory allocation of Insert into Array and Build Array functions

Solved!
Go to solution

@Ben wrote:

No, only when the resulting array is larger than what was previously allocated. Back when I was first exploring this detail I built an VI that repeatedly add a value to an array in a shift register and then tracked how long each iteration needed to complete.

 

At that time (LV 6i maybe) LV would start by allocating maybe 1000 elements for the array. every time if grew beyond the previous allocation, LV would double the size of the array (based on what I saw being used the Task Manager Performance).

 

So not every time, but only when required.

 

LV will also not release memory after a buffer is allocated since it is very expensive time-wise to allocate and deallocate memory.

 

Ben



This means that for every instance of build array function in my block diagram labview has allocated a certain amount of memory and every time i call that function it makes changes in that part of memory only ???

 

-Rishav

0 Kudos
Message 11 of 14
(562 Views)
Solution
Accepted by topic author rishavpreet

@rishavpreet wrote:

@Ben wrote:

No, only when the resulting array is larger than what was previously allocated. Back when I was first exploring this detail I built an VI that repeatedly add a value to an array in a shift register and then tracked how long each iteration needed to complete.

 

At that time (LV 6i maybe) LV would start by allocating maybe 1000 elements for the array. every time if grew beyond the previous allocation, LV would double the size of the array (based on what I saw being used the Task Manager Performance).

 

So not every time, but only when required.

 

LV will also not release memory after a buffer is allocated since it is very expensive time-wise to allocate and deallocate memory.

 

Ben



This means that for every instance of build array function in my block diagram labview has allocated a certain amount of memory and every time i call that function it makes changes in that part of memory only ???

 

-Rishav


Yes the previously allocated memory buffer is used provided there is enough space allocated. It is only when the allocation is not large enough that a larger buffer is allocated and the old data moved to the new allocation and the old buffer it returned to a cache that LV maintains to potentially be used elsewhere in the application.

 

You can investigate this more yourself by creating a test VI that uses code you you want to test out and then use;

 

Tools >>> Profile >>> Profile Buffer allocations

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 12 of 14
(547 Views)

@rishavpreet wrote:


This mean by using Replace array subset i will have to wire values one by one (basically using as many replace array subset functions as there are variables) where as in build array function i can wire values all at once and get my required array.  


You can use an array as subset. It does not matter how you replace elements, but if the big arrays resizes or not. Also, replace array subset is growable.

 

Again, don't use words, show us functional code.

Message 13 of 14
(545 Views)

@Ben wrote:

@rishavpreet wrote:

@Ben wrote:

No, only when the resulting array is larger than what was previously allocated. Back when I was first exploring this detail I built an VI that repeatedly add a value to an array in a shift register and then tracked how long each iteration needed to complete.

 

At that time (LV 6i maybe) LV would start by allocating maybe 1000 elements for the array. every time if grew beyond the previous allocation, LV would double the size of the array (based on what I saw being used the Task Manager Performance).

 

So not every time, but only when required.

 

LV will also not release memory after a buffer is allocated since it is very expensive time-wise to allocate and deallocate memory.

 

Ben



This means that for every instance of build array function in my block diagram labview has allocated a certain amount of memory and every time i call that function it makes changes in that part of memory only ???

 

-Rishav


Yes the previously allocated memory buffer is used provided there is enough space allocated. It is only when the allocation is not large enough that a larger buffer is allocated and the old data moved to the new allocation and the old buffer it returned to a cache that LV maintains to potentially be used elsewhere in the application.

 

You can investigate this more yourself by creating a test VI that uses code you you want to test out and then use;

 

Tools >>> Profile >>> Profile Buffer allocations

 

Ben


Thank you.

-Rishav

0 Kudos
Message 14 of 14
(538 Views)