LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory considerations while using the Queue and Functional Global techniques


nathand wrote:

If you're not seeing a buffer allocation then one isn't taking place.  Have you tried turning on the option (in preferences) to show constant folding?  If you're using a simple test VI you may find that the build array is folded into a single constant array, so no buffer allocation is needed - but your real life case is probably more complex.  I think you'll get the same results using either build array or reshape array, and both of them will cause a buffer allocation, according to this thread on LAVA (there's a question about reshape array towards the bottom of the first page, and I expect that build array is the same).


I just turning on the "show constant folding" option, and still it does not seem that any buffer is showing up withy a single 1D array on the input of the Build Array function. I read that thread on LAVA but am still a little confused. I could't tell from you post whether you think a buffer will be created in this situation. Is the Show Buffer Allocation tool the final authority or are you saying that even though it might say there is not buffer being created the circumstances may be complex and it will create one anyway when it is actually running the code. Thanks for your help :smileyhappy:
 
 
 
0 Kudos
Message 31 of 64
(2,000 Views)

I was just trying to say that if you're using a simple test VI to look at buffer allocations, make sure that it reflects the complexity of your actual application before making conclusions about where buffer allocations are occurring.  You can trust the show buffer allocation tool.  I was just making a guess, without seeing your code, and apparently I was wrong.  I am curious, though - if you change your build array to reshape array, do you get a buffer allocation?  If so, can you post that code (or an image of it)?

 

Be careful of spending too much time optimizing - have you spent some time profiling your code first to determine where the bottlenecks are?  Do you know how many times you call the code that you're trying to optimize?

0 Kudos
Message 32 of 64
(1,980 Views)
Dequeuing an array does not make a copy of the array (at least for single-element queues) despite what the buffer viewer says.  You can easily verify this yourself (see attached VI, LV8.6).  In a VI, create a large data set, enqueue it into a single-element queue, dequeue and do something with it (e.g. extract an element using the in-place element), then requeue it.  Now single-step through the VI with Task Manager active while watching the memory allocated to LabVIEW.  Set your data set to something easy to see (e.g. 10MBytes).  The only allocation will be the initial one.  This is why single-element queues outperform action engines for arrays.  It is all pointers.
Message 33 of 64
(1,955 Views)
The call by reference in the example is used to allow multiple instances of the same action engine.  The action engines in question are also reentrant, so you get distinct instances if opened with VI server.  Since they are reentrant, you cannot use them normally. I prefer the single-element queue method for multi-instance use, but it is just that, a preference.
0 Kudos
Message 34 of 64
(1,953 Views)

DFGray wrote:
Dequeuing an array does not make a copy of the array (at least for single-element queues) despite what the buffer viewer says.  You can easily verify this yourself (see attached VI, LV8.6).  In a VI, create a large data set, enqueue it into a single-element queue, dequeue and do something with it (e.g. extract an element using the in-place element), then requeue it.  Now single-step through the VI with Task Manager active while watching the memory allocated to LabVIEW.  Set your data set to something easy to see (e.g. 10MBytes).  The only allocation will be the initial one.  This is why single-element queues outperform action engines for arrays.  It is all pointers.

 

Would it be fair to say, then, that if the buffer allocation tool does not show an allocation then it's definite that one does not occur, but even if it does show an allocation, it's possible that one is NOT occurring?  Are there other cases where this would occur other than queues and similar by-reference types?
0 Kudos
Message 35 of 64
(1,947 Views)
nathand: It is helpful to know that no buffers will be created if the Show Buffer Allocation tool does not show any, that was something I was wondering. I am pretty new at this whole memory thing and trying to optimize my code for performance by reusing buffers. It is a more complex than it seems, but it is really changing the way that I write LabVIEW code. I am trying to post a pic for you but don't know how.... Well I know I have to go back and edit the post to be able to put the pic in, but can't seem to find the option to edit... :smileysad: The code that I am trying to optimize is inside of a loop that will be executed alot of times and deals with alot of data, it seems like it might be good to optimize this bit.

 

 DFGray: I wasnt able to open that VI, I have LV8.5. Would it be possible to post a 8.5 version?

0 Kudos
Message 36 of 64
(1,946 Views)
nathand: In that thread that you told me about on the LAVA board, they were discussing that sometimes when a buffer is shown to be created it is not the entire array. For example in that thread a buffer was shown to be created but it was for 3 attributes of an array... I think they were start, stride, and one other... So, maybe in this case the new buffer is just for a pointer... Not sure, but just a thought.
0 Kudos
Message 37 of 64
(1,943 Views)
To edit your post I beleive you need to submit the post first. Then go back to your post and on the right hand side of the title bar just above the kudos star graphic select options>>Edit Message. You only have a few minutes to do so.
Message Edited by GovBob on 01-14-2009 12:15 PM
Message Edited by GovBob on 01-14-2009 12:16 PM
Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 38 of 64
(1,919 Views)

Oh okay, thats why I couldnt edit it, it had been too long since the initial post. I thought I was going crazy because I editied one before but I couldnt find the edit option again. Thanks 

Message Edited by amaglio on 01-14-2009 12:33 PM
0 Kudos
Message 39 of 64
(1,911 Views)

I believe amaglio is correct, but cannot confirm it ( few people are here this early in the morning Smiley Wink ).  If the buffer viewer shows a copy, it is not necessarily a full copy.  It may be only a pointer copy, especially if the underlying data object is something like an array or cluster (pointer based objects in C).

 

I have run into occasions where the buffer viewer did not report a copy when one existed.  This usually happens at wire forks and on older versions of LabVIEW.  The gold standard is the operating system memory monitor (Task Manager in Windows).  If it matters, it is usually worth the time to single step through your code and validate the buffer viewer.

0 Kudos
Message 40 of 64
(1,894 Views)