• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: processing time & stack overflow
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: processing time & stack overflow


  • Subject: Re: processing time & stack overflow
  • From: Victor Yee <email@hidden>
  • Date: Mon, 27 Aug 2001 17:43:28 -0400

Just some points that may or may not apply:

Re: processing time

"Random number" is a call to the Standard Additions osax. It may be quicker to use "some" which is part of the AppleScript language (note that "some" takes different parameters).

Instead of

> to randomize(TheList)
> repeat with i from length of TheList to 1 by -1
> set current_item to (random number from 1 to i)
> tell TheList -- exchange item current_item with item i
> set temp to item i
> set item i to item current_item
> set item current_item to temp
> end tell
> end repeat
> return TheList
> end randomize

try this

to randomize(TheList)
repeat with i from length of TheList to 1 by -1
set current_item to some item of TheList's items 1 thru i
tell TheList -- exchange item current_item with item i
set temp to item i
set item i to item current_item
set item current_item to temp
end tell
end repeat
return TheList
end randomize

Re: stack overflow

> on juxtapose(_listsource, _juxtatext)
> set _listsource to my randomize(_listsource)
> set {AppleScript's text item delimiters, oldTIDs} to {{" "}, AppleScript's
> text item delimiters}
> set _listsource to _listsource as string
> write (_listsource) to _juxtatext starting at eof
> set AppleScript's text item delimiters to oldTIDs
> end juxtapose

There's a few unnecessary "set _listsource" statements here which might(?) contribute to memory usage. From what I can see, the randomize handler directly manipulates _listsource; there may be no need to "set _listsource" to the result. Also, there shouldn't be any need to reassign "_listsource to _listsource as string" as the coercion should be doable at write time.

on juxtapose(_listsource, _juxtatext)
randomize(_listsource)
set {text item delimiters, oldTIDs} to {{" "}, text item delimiters}
write (_listsource as string) to _juxtatext starting at eof
set AppleScript's text item delimiters to oldTIDs
end juxtapose

In which case, there would be no need to return a result from the juxtapose handler:

to randomize(TheList)
...
return
end randomize

It may also help to "flatten" your script. Handlers create stacks when they're invoked and (I think) AppleScript's stacks are limited in the amount of memory they're allowed to claim regardless of how much memory you throw at the applet. In any case, it wouldn't hurt as your script would easily accomodate a flattened structure.

There may also be a memory leak associated with intensive use of "text item delimiters" . But that's a faint recollection and I can't remember the details...

Victor


  • Follow-Ups:
    • Re: processing time & stack overflow
      • From: Timothy Bates <email@hidden>
  • Prev by Date: mail script...help needed
  • Next by Date: Re: mail script...help needed
  • Previous by thread: Re: processing time & stack overflow
  • Next by thread: Re: processing time & stack overflow
  • Index(es):
    • Date
    • Thread