AW: [Xotcl] destroy invoked by object move?

Scott Gargash scottg at atc.creative.com
Sun Mar 19 12:57:52 CET 2006






Thanks for your patience with me and my ignorance.  I had inferred that XOTcl was using Tcl
namespaces for storing object attributes (methods/variables/aggregations), but in my limited usage I
didn't realize that that was (legally) being used to advantage (making plain tcl commands become
xotcl methods via namespace import or the like).  So far I've been assuming the only legal way to
manipulate the object was through its handle (the object command).

Given my assumption, my thought was that you could cleanly substitute Tcl's namespace mechanism with
a hash-table lookup (attribute name -> Tcl_Obj *) for finding object attributes. Since each object
would have its own table, so there's no problem with name collisions (a attribute name is scoped by
the object you access it through, i.e., each object has its own set of slots), and if an object can
only be accessed through its handle, the handle is the only thing that needs to be exposed to the
interpreter.  None of the attributes would be visible to Tcl at all (Except to the extent XOTcl
exposed them.  You could still have traces and whatnot, but you'd have to use the object handle to
access them).  And if the objects were always accessed via a level of indirection, the raw object
handle (the true command name) is uninteresting too, so all objects be created with autonames in the
same namespace. And that this sort of an implementation (using a custom attribute lookup mechanism
instead of leveraging Tcl's) might potentially have some performance wins and/or new feature
possibilities.

But from your explanation, using Tcl namespaces to store object attributes is not just an
implementation decision, it's really part of the interface, so my approach would break XOTcl in
varied and uninteresting ways.

      Scott

Gustaf Neumann <neumann at wu-wien.ac.at> wrote on 03/18/2006 06:52:25 PM:

> Scott Gargash schrieb:
> >
> > Gustaf Neumann <neumann at wu-wien.ac.at> wrote on 03/18/2006 01:39:35 PM:
> > >
> > > I do not see much evidence of a speed increase when adding a layer of
> > > indirection for every object access.
> >
> > Well, for example, it might be possible to get rid of namespaces in
> > the implementation.
> >
> thinking about getting rid of namespaces is a different theme, this can
> be done as well without "strongly aliased objects".
>
> namespaces are  pretty essential  in tcl. every command name lookup
> works through a namespace. xotcl uses
> tcl-namespaces for methods (procs and instprocs), for variables, and for
> aggregations. certainly, this could be
> implemented differently, frequently we have to fight with namespaces,
> but the idea was to reuse concepts
> from tcl in xotcl. Using tcl-namespaces has many advantages as well:
> currently, we can rename tcl-procs
> or tcl-commands to make it methods in xotcl; or we can namespace-import
> procs/cmds from tcl as
> methods/instmethods etc. into xotcl with the standard tcl-commands.
> >
> > If the access to the object is always through the reference and the
> > true object was never visible, you might not have to create a new
> > namespace (on demand or not)
> >
> i can't follow the argument.... what ist the relationship with the
> visibility? namespaces are used for various purposes:
> methods are tcl_procs or tcl-commands and have to "live" somewhere, in
> tcl they live in namespaces.
> one can certainly implement this differently as in tcl, as for example
> using hash-tables only, but this is not
> related to visibility. btw, if you never show the real name to the
> application developer, it will be hard to create
> multiple references other than by creating an alias of the alias.
> > or ever move an existing object to make it a child of another object.
> >  The parent/subobject relationship could be inferred from the alias's
> > location in the namespace, or even tracked in child/parent hash tables
> > if you wanted to support object relationships beyond a tree (DAGs),
> > but it would not be a property of the object's location.  If objects
> > never moved, everything could live in the same namespace, and just
> > tracked via the object hashes.
> >
> > And is method dispatch done via a command lookup? If so, an invariant
> > method location should allow command lookup to be elided.
> >
> whatever "same namespace" means (see above). note that we have multiple
> identical method names in procs/classes,
> they can't live in the same namespace. if the nesting relationship is
> realized via the namespaces of the aliases,
> these have to be created as well since they will most likely not exist.
> This way, they namespaces are moved
> out of the xotcl objects, but introduced at different places, where they
> are more complicated to manage.
> some interactions with namespaces will be even more complicated as they
> are now: you have to
> deal with cases, where e.g. someome deletes the alias (e.g. via "rename
> myreference {}")  or deletes
> the namepace, where the alias lives in.
> >
> >
> > Of course, since I'm the one who keeps asking "How do I do this?"
> > questions, I'm probably completely wrong.
> > BTW, does invocation via an alias have any overhead?  I would guess
> > not as it's (seems like) a string->Tcl_Obj mapping, the same as a
> > native command lookup, but I don't know.
> >
> an "interp alias" has a certain overhead, since it is an additional
> command invocation.
> Try the following; if you increment the loop counter in the for loop to
> e.g. 1000,
> you will get a "too many nested evaluations" error. you will see, the
> last test will be
> the slowest by far.
>
> ==========================================================
> proc t {cmd {txt ""}} {
>   set n 100000
>   set ms [lindex [time [list time $cmd $n] 10] 0]
>   puts "[format %7.4f [expr {$ms*1.0/$n}]]ms for $cmd ($txt)"
> }
>
> proc x {} {set x 1}
> interp alias {} myset {} set
> interp alias {} myx {} x
> interp alias {} myx1 {} x
>
> for {set i 1} {$i < 100} {incr i} {
>   set i1 [expr {$i+1}]
>   interp alias {} myx$i1 {} myx$i
> }
>
> t {set x 1} "set"
> t {myset x 1} "myset"
>
> t {x} "x"
> t {myx} "myx"
> t myx$i1 myx$i1
> ==========================================================
>
> It is however possible to implement zero-overhead aliases
> with the tcl c-api, at least in certain situations, when one does not
> care about someone else replacing commands on the fly with
> global effects. I have implemented such things by myself.
>
> best regards
> -gustaf neumann
>
>

> ForwardSourceID:NT00007E9E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://alice.wu-wien.ac.at/pipermail/xotcl/attachments/20060319/1476ff6f/attachment.html


More information about the Xotcl mailing list