Is there a faster way?
T. R. Ponn
alptex2 at orwell.net
Sun Jun 29 10:22:01 EDT 2003
Hello,
I have a binary file that I want to divide up between 2 variables,
depending on user input.
With memBank value "01"
a file like this: "12345678"
would end up: "1357" in variable bank0 and "2468" in bank1.
With memBank value "10" the same file would end up: "2468" in variable
bank0 and "1357" in bank1
The file can be sizable (maybe 128MB), though far more typical would be
around 8 MB. The following code snippet accomplishes the feat in about
25 seconds for a file size of 8MB...using my G4/500MHz, OS 9.2.2 and
Rev1.1.1.
on eenieMeenieMinieMo fileContents
put the length of fileContents into fileLength
if char 1 of memBank=0 then --memBank="01", so start with even bank
repeat with b=1 to ((trunc(fileLength/2))+1)
put char ((b*2)-1) of fileContents after bank0
put char (b*2) of fileContents after bank1
end repeat
else --memBank="10", so start with odd bank
repeat with b=1 to ((trunc(fileLength/2))+1)
put char ((b*2)-1) of fileContents after bank1
put char (b*2) of fileContents after bank0
end repeat
end if
end eenieMeenieMinieMo
Size of code is of no consequence (I've already cut the length in
half...it's just easier to understand what I'm trying to accomplish in
this form), but speed is. Any ideas on how to speed this up? The
utilization of arrays seemed to have little effect on it. Thanks for
any help you can lend!
Best Regards,
Tim Ponn
More information about the use-livecode
mailing list