LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

In-place array subset replacement

Is there a way to do "in-place" array subset replacement? The example VI I have included is somewhat contrived, but it shows the problem.

I need to be able to allocate and use some fairly good sized buffers (i.e. around 16 MB). In the example code if I allocate a "big" array and then try to set the values of the array to the iterator % 256 it becomes EXTREMELY slow. The reason being that "Replace Array Subset" always makes a copy of the array and returns it. If you try the code with an array size of say 20000 and then try 1000000 you will notice a HUGE difference in speed.

So, I'm hoping to find a way to replace an element or subarray in-place or in other words without having to make a copy of the array. I'm hoping
that there is some easy way that I have missed.

Thanks.
0 Kudos
Message 1 of 4
(3,027 Views)
You are forcing a copy of the array by using a local variable. Eliminate it and things should go a lot faster. I've attached your VI modified to use a shift register.
Message 2 of 4
(3,027 Views)
Thanks a bunch - this is much faster. I will just have to make sure that I also do this in the general case.
0 Kudos
Message 3 of 4
(3,027 Views)
Hello,

Dennis is correct; a local variable will force a copy of the data. In general, LabVIEW will try to do an in-place replacement whenever possible. However, depending on what is happening with the data before and after the replacement, LabVIEW may make a copy.

A good KnowledgeBase discussing buffer allocation is Determining When and Where LabVIEW Creates a New Buffer. There is a small utility at the bottom of the page that will show you where data copies are happening.

It sounds like you've been able to solve your problem. If you have any further questions, feel free to post again.

Grant M.
National Instruments
0 Kudos
Message 4 of 4
(3,027 Views)