[ANN] Process-Specific Variables
"Martin v. Löwis"
martin at v.loewis.de
Wed Mar 14 07:12:57 UTC 2007
Giovanni Corriga schrieb:
>> except that the value of the variable is only valid in the scope of the
>> current process.
>
> Isn't this similar to what DynamicBindings does?
Indeed. I see two important differences, though:
- different (better?) implementation strategy: DynamicBinding is based
on exceptions to find the innermost binding; this requires a stack
walk for a matching exception handler. It then uses a linked list of
dictionaries for lookup. So lookup time is typically linear with the
stack depth, and then linear with the depth of the binding stack.
My implementation offers constant-time lookup (if there are no
dictionary collisions), as it has the current value always in the
current process (getting the current process, getting a slot of it,
fetching the reference to the global class, and passing that as
a dictionary key are all constant-time).
- separation of process-local and dynamic variables: in DynamicBindings,
you can rebind a variable at any point in time, and it uses the
innermost binding (whereever that is). In my solution, dynamic
variables can be only set, then read, but not written (i.e. rebound).
Experiences with dynamic scoping in LISP show that they might be
difficult to understand; I expect that making them read-only gives
more readable code, as you don't need to worry that a function
you call may change the value behind you.
OTOH, process-local variables are read-write, but they don't have
any nesting to them. This is, AFAICT, not directly supported in
DynamicBinding, as you need to create at least one scope
explicitly to establish per-process values. In process-local
variables (called TLS elsewhere), every Process will have it own
value for it right from the start, using a default mechanism.
Regards,
Martin
More information about the Squeak-dev
mailing list
|