09-29-2008 07:25 AM
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
09-29-2008 11:09 AM
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.
09-29-2008 01:45 PM
Hi,
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
09-29-2008 01:53 PM
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?
09-29-2008 02:08 PM
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.
09-29-2008 02:09 PM
09-29-2008 04:23 PM - edited 09-29-2008 04:24 PM
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).
09-30-2008 02:13 AM
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
09-30-2008 02:21 AM
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?
09-30-2008 03:02 AM - edited 09-30-2008 03:02 AM
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.)