Speeding up array initialization
jbv.silences at Club-Internet.fr
Sun Nov 23 02:26:25 EST 2003
> First, remember that you don't have to initialize an array unless you
> have values you want in it.
I know, but in my case, I need at least 5 to 10 arrays of 100*100 minimum,
each one initialized with various values, and then re-initialized to other
(or process parts of the data already stored in the arrays) on the fly
to user actions...
IOW I can't have the user waiting 5 times 115 ticks before he can use the
At first, I thought of storing these data in variables made of lines &
since I had found a way to re-initialize such variables in less than 1
But I found out that processing the same data in arrays is 25% to 30%
So I was in search for a fast way to initialize arrays...
As for your example of using the split command.
OK, I get it now. But I'm afraid it won't be of any use to me, since
the content of the variable to be used by split cmd might be even slower
initializing the array with 2 nested repeat loops...
A nice feature would be to be able to use "replace" with arrays.
This way, I could initialize 1 array at startup (with zeros for instance),
and then duplicate it under a different name, and use :
replace 0 with myNewData in MyNewArray
Mmmh... Actually, a new idea just crossed my mind :
I could also build 1 variable at startup, which would contain the
and then use the following script when I want to (re-)initialize an array
put myOriginalVar into myNewVar
replace "a" with "0" in myNewVar
split myNewVar using return and space
I guess this should work pretty fast (have to test it though)...
I could also write an external in C that would give me access to all
arrays & structures in C...
Well, anyway, all these solutions are a bit tricky... I mean : there's
still a lot of space for improvement of arrays in MC/Rev...
Thank you all anyway,
> In the case you listed below, what you want is something like this:
> 1,1 a
> 1,2 b
> 1,3 c
> 1,4 d
> 1,5 e
> 2,1 f
> 2,2 g
> 2,3 h
> 2,4 i
> 2,5 j
> In the above the separator is a space, for ease of use in email. You
> need to use something that is guaranteed not to be in your index or
> Given the above in a variable x,
> split x using return and space
> would give you the array you want.
> So now you just need a way to go from the lines you have to the
> information above. Something like this will work:
> put empty into tNewData
> put 0 into tLineCounter
> repeat for each line L in tData
> add 1 to tLineCounter
> put 0 into tItemCounter
> repeat for each item T in L
> add 1 to tItemCounter
> put tLineCounter,tItemCounter && T & cr after tNewData
> end repeat
> end repeat
> Geoff Canyon
> gcanyon at inspiredlogic.com
> On Nov 22, 2003, at 1:49 PM, jbv wrote:
> >> You can change your delimiters in the split, JB. (The second cannot
> >> be
> >> null, though.) Build your value to be split appropriately.
> > Well, thanks for the advice, but I've already tried the split cmd in
> > many
> > ways, but with no success...
> > Here's an example :
> > I have a variable S made of 2 lines of 5 items each :
> > line 1 : a,b,c,d,e
> > line 2 : f,g,h,i,j
> > how do I use the split cmd so that I get a 2 dimensions array S in
> > which :
> > S[1,1] = a
> > S[1,2] = b
> > S[2,1] = f
> > S[2,2] = g
> > and so on...
> > Thanks,
> > JB
> > _______________________________________________
> > use-revolution mailing list
> > use-revolution at lists.runrev.com
> > http://lists.runrev.com/mailman/listinfo/use-revolution
> use-revolution mailing list
> use-revolution at lists.runrev.com
More information about the Use-livecode