stack/table overflows on storing complex scripts
stack/table overflows on storing complex scripts
- Subject: stack/table overflows on storing complex scripts
- From: has <email@hidden>
- Date: Wed, 21 Aug 2002 14:33:21 +0100
Hi,
Getting ticked off again at the problems encountered when trying to store a
script object that contains a large number of other script objects.
Example: I've just implemented some new stack/queue objects that store
values in an object-based linked list (1), and find these will break a
'store script stackObj' command if the linked list is more than 540 items
long.
Interestingly enough, I find that reimplementing the stack object's nodes
as records instead of script objects also breaks, only this time it breaks
while adding items to the stack object (again, somewhere around the
540-item mark). At least using script objects you can keep adding nodes
[almost?] indefinitely; you only get punished if you attempt to dump the
object to file.
This sort of suggests that there's some inherent limits on how deeply
objects may be nested in AS (although where this limit actually bites the
user varies for different object types). Or is the relationship more
complex than that?
I know this isn't a major issue for most users (overflows on tokenising
strings and various 32KB limits are much bigger hassles, and ones that
affect the majority), but I wanted to see if anyone knew anything more
specific on it as there's few things more annoying than writing really cool
new code and then having to glue health warnings all over it.
Thanks,
has
(1) I'm aware of AS's built in linked list types, but as Chris N has
indicated that these may [not unreasonably] be dropped in a future AS
version it seems safest to roll my own.
p.s. Here's the code if anyone wants to play with it:
======================================================================
on newStack(maxSize)
script
property class : "stack"
property _linkedList : missing value
property _size : 0
property _maxSize : maxSize as integer
--
on addVal(theValue)
if _size is _maxSize then error "Stack overflow." number 311
set _size to _size + 1
script node
property _val : theValue
property _chain : _linkedList
end script
set _linkedList to node
return
end addVal
--
on removeVal()
set _size to _size - 1
if _size is -1 then error "Stack underflow." number 310
set theValue to get _linkedList's _val
set _linkedList to get _linkedList's _chain
return theValue
end removeVal
end script
end newStack
property stackSize : 540 -- 541 will fail
on foo()
set stk to newStack(100000)
repeat with i from 1 to stackSize
tell stk to addVal(i)
end repeat
return stk
end foo
store script foo() in file "frank:test" replacing yes
======================================================================
--
(My email address has changed from <email@hidden> to
<email@hidden>. Please update your address books accordingly.)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.