LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do to avoid unnecessary copy of the array?

Solved!
Go to solution
0 Kudos
Message 1 of 13
(4,556 Views)

Question.

 

Why are you worried about memory copies on an array that only has 1000 elements.?

0 Kudos
Message 2 of 13
(4,532 Views)

@RavensFan  已写:

Question.

 

Why are you worried about memory copies on an array that only has 1000 elements.?


Hi,

0 Kudos
Message 3 of 13
(4,518 Views)

What exactly are you doing to the arrays when you modify them?  I would use In Place Element Structure inside the subVI's.  But I don't think you really need to do that.  LabVIEW is pretty good about managing memory as long as you aren't doing anything crazy.  I feel like you are trying to solve a problem that doesn't exist.

Message 4 of 13
(4,510 Views)

I'm with RavensFan here.  The compiler already does a lot to limit array copies.  If you are REALLY worried, turn off debugging in your subVIs.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 13
(4,505 Views)

@RavensFan  已写:

What exactly are you doing to the arrays when you modify them?  I would use In Place Element Structure inside the subVI's.  But I don't think you really need to do that.  LabVIEW is pretty good about managing memory as long as you aren't doing anything crazy.  I feel like you are trying to solve a problem that doesn't exist.


Thank you for your advise. I usually use Replace-Subset function and sometimes In-Place structure inside the subVIs. Maybe I am just curious about how LabVIEW handles the memory and data passes.

0 Kudos
Message 6 of 13
(4,494 Views)

@crossrulz  已写:

I'm with RavensFan here.  The compiler already does a lot to limit array copies.  If you are REALLY worried, turn off debugging in your subVIs.


Thanks,it seems better to believe in the compiler.

0 Kudos
Message 7 of 13
(4,492 Views)
Solution
Accepted by topic author Heartnode

You have several options, but it also all depends how efficient the code of your subVIs is. If you blow it there (e.g. with resizing operations excessive branching, or local variables, all bets are off. I am sure we could give much more targeted advice if we could actually see the various VIs used. What do they do? How different are the subVIs? Could there code be merged into one, e.g. with an addition input giving the desired range?

 

Still, all this seems pointless for only 1000 elements, but might be useful for gigantic arrays.

 

  1. Do nothing. The compiler can often figure out inplaceness, even across subVI boundaries. (See also)
  2. To avoid the subVI overhead, you can inline the subVIs.
  3. Carry your array data in a DVR instead of a shift register.
  4. parallelize by using the IPE/split array feature. (looks like you have overlapping ranges, so this will not work here)
  5. of course turn off debugging as has been mentioned already
  6. ....

If you are concerned, look at allocation dots, and do detailed benchmarking and testing of the various possibilities. This is hard to do right, though. Are you concerned more about memory or execution speed?

Message 8 of 13
(4,487 Views)

Depending on what version of LabVIEW you are using, you can use the IPE structure with the array split primitive to modify a subset of your array inline without any copies.

 

But depending on the version of LabVIEW the IPE structure may make a copy, read the entire discussion here:

https://forums.ni.com/t5/LabVIEW/LabVIEW-2015-Buffer-Allocation-Bug/m-p/3300392/highlight/true#M9655...

 

I believe this bug has been quashed in newer versions, 2017 and later??, and the copy does not occur.

 

mcduff

0 Kudos
Message 9 of 13
(4,481 Views)

@mcduff wrote:

Depending on what version of LabVIEW you are using, you can use the IPE structure with the array split primitive to modify a subset of your array inline without any copies.


As I mentioned, this won't work here because the ranges overlap:

[0..199], [150..799], [750..999]

 

0 Kudos
Message 10 of 13
(4,474 Views)