Gary Rubin Posted August 25, 2006 Report Share Posted August 25, 2006 Hello all. First some background: I want to essentially create an Intensity Plot that scrolls down instead of to the left. There are a couple of ways to implement this, and I wanted to determine the speed trade-off associated with using Delete from Array and Build Array vs. Replace Array Subsets. I've gotten it working with no problems, and found that the Replace Array Subset approach is much faster. Along the way, however, I discovered something that perplexed me a bit and was wondering if any of you gurus out there had any thoughts on this. The attached subvi does the following: If the graph is not "full" yet, it simply replaces a column in a preallocated array. If the graph is full, it deletes the first column and tacks on a new one. If use "show buffer allocations", I see an allocation at the output of the build array, at the tunnel, and at the indicator. The Replace Array Subset solution (also attached) does not have these buffer allocations, and therefore runs much faster even in the False case in which the 2 subvi's are doing the same thing. That leads to my question: Aren't some of those buffer allocations redundant? Why is there an allocation at the tunnel AND at the indicator, while there's no similar allocation in the Replace Array Subset implementation? Some day, maybe I'll actually understand and therefore not be surprised by some of Labview's allocations. Thanks, Gary Download File:post-4344-1156517054.vi Download File:post-4344-1156523406.vi Quote Link to comment
Ton Plomp Posted August 26, 2006 Report Share Posted August 26, 2006 Why is there an allocation at the tunnel AND at the indicator, while there's no similar allocation in the Replace Array Subset implementation? Good question and observation, I *think* i know the answer. I read once on the NI forums to force LabVIEW to handle arrays inplace (eg. on the same memory location) in a subvi there should be (at least) one case where the data is not allocated, this would force the other cases to use inplaceness also. I think this is the main difference in both VI's, maybe if you add another case (-1) where the data just flows through gives you a better solution. Ton Quote Link to comment
bsvingen Posted August 26, 2006 Report Share Posted August 26, 2006 Whenever you change the size of an array, memory need to be allocated/deallocated. Therefore, if the array dim entering the tunnel on one side is different than the dim on the other side, labview creates a buffer. Replace array subset conserve the dim, while build array changes the dim. This has to be so even though the dimension does not really change in your vi, because LV has no way of knowing the the dim in the new data is the same as the dim in the deleted data. Quote Link to comment
Gary Rubin Posted August 26, 2006 Author Report Share Posted August 26, 2006 Whenever you change the size of an array, memory need to be allocated/deallocated. Therefore, if the array dim entering the tunnel on one side is different than the dim on the other side, labview creates a buffer. Replace array subset conserve the dim, while build array changes the dim. This has to be so even though the dimension does not really change in your vi, because LV has no way of knowing the the dim in the new data is the same as the dim in the deleted data. So that would explain the allocation at the tunnel, but why another allocation at the indicator? Quote Link to comment
bsvingen Posted August 26, 2006 Report Share Posted August 26, 2006 So that would explain the allocation at the tunnel, but why another allocation at the indicator? Thats a good question Sorry, but i din't see that at first. I think the answer is that the control and indicator have separate memory allocation rules, different from wires and subroutines. The indicator can have different dimension compared to the control, so a separate buffer for the control is set. I ALLWAYS make sure that i do not change array dimension in subroutines unless that is part of the functionality. I learned that from trial and error and from boards like this. I think your example show the impotrance of this, although *exactly* what is going on inside the compiler is still a bit mystic to me. Quote Link to comment
Gary Rubin Posted August 26, 2006 Author Report Share Posted August 26, 2006 Thats a good question Sorry, but i din't see that at first. I think the answer is that the control and indicator have separate memory allocation rules, different from wires and subroutines. The indicator can have different dimension compared to the control, so a separate buffer for the control is set.I ALLWAYS make sure that i do not change array dimension in subroutines unless that is part of the functionality. I learned that from trial and error and from boards like this. I think your example show the impotrance of this, although *exactly* what is going on inside the compiler is still a bit mystic to me. Thanks, I'll try Ton's suggestion too, although at this point, all of this is mostly academic, since I have the other version of the subvi that works more efficiently. Michael A., if you happen to read this, what do you think of an Optimization forum? Gary Quote Link to comment
Gary Rubin Posted August 28, 2006 Author Report Share Posted August 28, 2006 I think this is the main difference in both VI's, maybe if you add another case (-1) where the data just flows through gives you a better solution. That did not change anything, which I guess I would expect based on bsvingen's explanation: The indicator can have different dimension compared to the control, so a separate buffer for the control is set. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.