LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write formatted 2D data into a file

Solved!
Go to solution

@altenbach wrote:

@Artem.SPb wrote:

 

When you use "insert into array" each iteration you waste memory and time


It's not with every iteration. Also "built array" does the same thing so there is no difference.


do you mean that this 2 ways has no difference?

arr1.png


I see that 2nd twice faster

 

arr2.png

 

arr3.png

0 Kudos
Message 11 of 18
(1,221 Views)

Artem.SPb wrote: do you mean that this 2 ways has no difference?

 

You cannot compare these two, because they are completely different. There will be a difference.

 

(I also thougth we are comparing "insert into array" with "built array", not some random other code.)

 

Since you chose to use a while loop instead of a FOR loop, the final array size is typically not know to the compiler, while in the lower part the final size is fully determined.

For the upper code, you would substitute a FOR loop autoindexing at the output. No shift register even needed.

0 Kudos
Message 12 of 18
(1,210 Views)

@Artem.SPb wrote:

I see that 2nd twice faster

arr2.png

 


 

As said already, you are comparing apples and oranges because your left code only creates 3 columns while the right code create four columns.

You are also reading a control inside the first frame, an operation that you should not incude in the timing.

 

Here are two examples comparing apples and apples. Now the left side is even slightly faster.

 

 

 

If we need to include conditional appending as in the original problem, none of the two code fragments are appropriate anyway.

 

 

 

 

0 Kudos
Message 13 of 18
(1,205 Views)

@altenbach wrote:

Artem.SPb wrote: do you mean that this 2 ways has no difference?

You cannot compare these two, because they are completely different. There will be a difference.

 

(I also thougth we are comparing "insert into array" with "built array", not some random other code.)

 

Since you chose to use a while loop instead of a FOR loop, the final array size is typically not know to the compiler, while in the lower part the final size is fully determined.

For the upper code, you would substitute a FOR loop autoindexing at the output. No shift register even needed.


You are right, for loop is better, but look at original code, Pavel_47 uses case in loop, so compiler don't knows array size. This is reason why I use while loop in my test.
I mean that build array at one step is better than build it in case-structure step by step.

0 Kudos
Message 14 of 18
(1,197 Views)

@Pavel_47 wrote:

How to save column_0 in integer format, other columns - in floating point ?

 


You might not even need the 2D array, you could just stream the data to the file directly. Now you are guaranteed not to run out of memory (e.g. if you keep the code running while you go on vacation :o).

 

 

 

 

(If you also want to keep the 2D array, there are also better ways....)

 

Download All
0 Kudos
Message 15 of 18
(1,195 Views)

@Artem.SPb wrote:
You are right, for loop is better, but look at original code, Pavel_47 uses case in loop, so compiler don't knows array size. This is reason why I use while loop in my test.

I mean that build array at one step is better than build it in case-structure step by step.


If you don't know the array size, you cannot use the right code. So what's your point?

0 Kudos
Message 16 of 18
(1,192 Views)

@altenbach wrote:

@Artem.SPb wrote:
You are right, for loop is better, but look at original code, Pavel_47 uses case in loop, so compiler don't knows array size. This is reason why I use while loop in my test.

I mean that build array at one step is better than build it in case-structure step by step.


If you don't know the array size, you cannot use the right code. So what's your point?


You want to fight about or offer the best option to Pavel?
I wrote, it is better to create an array at once, rather than a step-by-step using the case structure. Where is the error in my words?

0 Kudos
Message 17 of 18
(1,182 Views)

@Artem.SPb wrote:
You want to fight about or offer the best option to Pavel?
I wrote, it is better to create an array at once, rather than a step-by-step using the case structure. Where is the error in my words?

No fight, just wondering what you are trying to say....

 

In your "solution" you are building the 2D array one row at a time. I thought you were trying to improve on that in a later post, but you were talking about building the rows. The rows are so short that the preemptive over-allocation by the compiler will probably take care of things without needing memory reallocations, so it's not such a big deal.

 

(Autoindexing at the right loop boundary would be equivalent to your building of the 2D array, just simpler code!)

 

In contrast, my suggested solution does not even built an array. Hard to beat that 😄

 

If we would know the final array size beforehand, other good solutions will be possible. Growing arrays without size limit is never a good idea because of memory issues. I am sure it would take much longer to run out of disk space. Arrays need to be contiguous in memory, while files on disk can be fragmented.

0 Kudos
Message 18 of 18
(1,176 Views)