Speeding up array initialization

Geoff Canyon gcanyon at inspiredlogic.com
Sun Nov 23 11:44:02 CST 2003


Can we back up a moment? I'm not sure I understand what the real 
problem is here. Can you describe in more detail what you want to 
accomplish.

I did a quick test on a G3 400, and initializing a 100,100 array to "a" 
took less than 20 ticks.

That's fast, but even so I'd be looking for ways to be responsive to 
the user before all the data is in place. Initialize in pieces, and 
only make the user wait if he/she asks for something that hasn't yet 
been initialized.

But again, what's the actual goal?

regards,

Geoff Canyon
gcanyon at inspiredlogic.com

On Nov 22, 2003, at 11:26 PM, jbv wrote:

>
>
> Geoff,
>
>> 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
> values
> (or process parts of the data already stored in the arrays) on the fly
> according
> to user actions...
> IOW I can't have the user waiting 5 times 115 ticks before he can use 
> the
> app
> again...
> At first, I thought of storing these data in variables made of lines &
> items,
> since I had found a way to re-initialize such variables in less than 1
> tick.
> But I found out that processing the same data in arrays is 25% to 30%
> faster.
> 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
> building
> the content of the variable to be used by split cmd might be even 
> slower
> than
> 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
> following :
> 1,1 a
> 1,2 a
> 1,3 a
> .....
> 100,100 a
>
> 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,
> JB
>
>
>
>>
>> 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
>> data.
>>
>> 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
>>
>> regards,
>>
>> 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
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list