LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does the string concatenate slow a loop?

I am concatenating two strings using the concatenate function in a For Loop, and executing the loop 25000 times. The loop executes as if there is a delay in the loop. I am running this test in normal execution mode, NOT Highlight mode.
I understand there are more efficient ways to do this but I am trying to understand the concept why the concatenate slows execution soo much.
Can anyone provide me with some knowledge on this topic?
0 Kudos
Message 1 of 4
(3,235 Views)
The concatenate strings function has to create a new string for the output string and destroy the input strings. This is much different from the replace substring (which is much more efficient), where no memory is allocated or destroyed, but rather, the output uses the same memory as the input (only some of the values stored in the memory locations are changed).

Allocating and dealocating memory are time consuming. The larger the memory being operated on, the more time it takes.

-Jim
Message 2 of 4
(3,235 Views)
> I am concatenating two strings using the concatenate function in a For
> Loop, and executing the loop 25000 times. The loop executes as if
> there is a delay in the loop. I am running this test in normal
> execution mode, NOT Highlight mode.
> I understand there are more efficient ways to do this but I am trying
> to understand the concept why the concatenate slows execution soo
> much.
> Can anyone provide me with some knowledge on this topic?

Is there anything else in the loop? Perhaps an update to a control or
indicator? Or maybe you are building an array of the output strings.
While concatonate will have to do memory management, I was able to do
25,000 in milliseconds. How many milliseconds depends on the size of
the string, but it is quite fast.


Greg McKaskle
0 Kudos
Message 3 of 4
(3,235 Views)
Thank you Jim!

I was asked this morning about what "destructive reads" are.

I thought about the re-use of buffers in a CIN but I was drawing a blank otherwise.

I had never stopped to think about what happened to the input string (I avoid long strings like the plague).

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 4
(3,235 Views)