LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create 2D array of 1D aray of String

Locals if carefully used might be ok.  They tend to be abused and lead to nightmares (even in the daytime) 😮  Local Variables may not maintain dataflow which can lead to race conditions.

 

If you can, the use of shift registers is the more memory efficient way.  Also a better coding practice as you can avoid race conditions that may be created by using Local Variables.

 

As far as which is more time efficient, I don't know if there is a difference, if there is, it is probably negligeable, unless you are using many Locals which is a practice to be avoided.

 

In short, if you can, go for the shift registers.  

 

R

Message 11 of 34
(2,005 Views)

ritesh024 wrote:

If i dont initialize the Array, it doesn't put any value into it. 


Yes, you cannot "replace" an  array element if nothing is there. Of course you can grow the array at runtime, e.g. using built array, but that is significantly more expensive, because any change in array size will force a new copy of the array in memory. The problem is siginficantly bigger for complicated data structures such as this if you allow variable sizes for the inner and outer arrays.

 

Do you know the final array size? Do you get the array elements in a suitable order? Is the "inner" array always the same lenght? How about the size of the "outer" (2D) array?

 

There are many ways to create such an array from scratch. It could be as easy as generating the 2D outer array using autoindexing in a stack of 2 FOR loops.

Message 12 of 34
(1,987 Views)

Hi,

Thanks for your replies. :smileyhappy:

 

Thing is i am importing the data from the file to a 2D array. and the file is controlled by the user. he can make any changes to the file, and when the program is run, i want to load the file into an array.

Though i can set the maximum value to the size of an array, both 2D and the inner array.

 

Then, the ques arises if i set the maximum size it will allocate memory for the max size of an array, where many fields could be empty.

is it possible that even if i set the max value to the array, it will allocate memory only if i put something into it ?

 

And yes, regarding the "built array" function, you mentioned that every time that function is used, it will make another copy of that array in the memory. Now, will it remove the previous copy from the memory of keeps both the copies in the memory ?

 

Thanks,

Ritesh 

 

 

 

 

0 Kudos
Message 13 of 34
(1,975 Views)

Actually, strings are stored differently to numerics so I am not fully clear how these things are handled in this particular case.

 

Will any of the sizes/dimensions ever change after the file is read?

 

What is the structure of the file? Can you give an example? How do you read it?

Message 14 of 34
(1,971 Views)

I am attaching a sample file showing the structure of the original file.

0 in the file represents the end of row and 1 represents the end of column.

Once the file is read, i display the data  on the Table. The user can modify data from the table and i need to save the modified data back to the file.

 

I read the file line by line and look string or number.

if '0' is encountered, i increment the row by 1 and if '1' is encounterd i increment the column by 1 and set roe to 0.

0 Kudos
Message 15 of 34
(1,967 Views)
sorry, forgot to attach the file in my previous post.
0 Kudos
Message 16 of 34
(1,965 Views)

So, if I understand you correctly, the number or rown/colums of the 2D array and the number of elements in the 1D array is variable. Is this correct?

 

How big is the array? Here's a quick way how you could read in the file as a string and parse it for the desired data structure (LV8.5.1). Modify as needed.

 

(note that the various delimiter constants are set to \-codes display).

 

Message Edited by altenbach on 09-29-2008 02:24 PM
Download All
Message 17 of 34
(1,945 Views)

Unfortunately i couldn't run your code as i am using LV8.5 and haven't yet upgraded myself to LV8.5.1.

The size of the outer 2D array is 10*4(maximum) and the inner 1D array is 10(max).

 

I am attaching the piece of Code i wrote to get the desired output.

Pls have a look at it and let me know if there's a better solution to it in LV8.5.

 

Thanks,

Ritesh

 

 

Download All
0 Kudos
Message 18 of 34
(1,906 Views)

ritesh024 wrote:

Unfortunately i couldn't run your code as i am using LV8.5 and haven't yet upgraded myself to LV8.5.1.


You should be able to run 8.5.1 code with version 8.5. have you even tried? What kind of error did you get?

Message 19 of 34
(1,903 Views)

ritesh024 wrote:

Pls have a look at it and let me know if there's a better solution to it in LV8.5.


Yes, use my code. To get the desired arrangement, simply transpose the 2D array at the end.

 

(You should also delete the last line with the lone zero from the input file).

 

 

 

 

(Your program is way too complicated. 🙂 It is very expensive to read a file line-by-line and that "readlocal-modify-writelocal" dance shoud really be replaced by a shift register.)

Message Edited by altenbach on 09-30-2008 01:02 AM
Message 20 of 34
(1,902 Views)