Way to speed up append strings?

Ken Ray kray at sonsothunder.com
Sun Nov 14 10:31:03 EST 2004


On 11/14/04 9:20 AM, "Frank Leahy" <frank at backtalk.com> wrote:

> I have a preferences file that is fairly large (30K+), and it's created
> on-the-fly using "append string" functions, e.g.
>     put "this data and that data..." after thePrefs
>     put "some more data..." after thePrefs
>     put "even more data..." after thePrefs
> 
> This is getting slower than I'd like, and it appears that the slowdown
> is because the append functions are getting slow.  I'm guessing that
> RunRev is reallocating memory on each append, then copying the existing
> string and the appended string into the newly allocated memory.  And
> because I have lots of little appends this really slows things down
> (and no, there's no way to make the appends longer and therefore
> fewer...).

Frank, I don't know if this would help, but is there a way in your code that
you can declare a temporary empty variable, and then do a handful of small
appends to that var to make it a "longer" variable that you can then append
to the main var? That way, the main var only gets longer appends added to
it, and each of those is made up of a handful of smaller appends so it
doesn't take long to create.
 
> If not, I'll have to go to a "write to temp file and then re-read from
> temp file" type of solution (because writing and reading to a temp file
> appears to be significantly faster than doing lots of little appends).

Really? I'm surprised that read/write to a file is actually faster? Good to
know...

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list