[Xotcl] Expand init arguments and custom destructor

Stefan Sobernig stefan.sobernig at wu.ac.at
Tue Feb 8 09:58:03 CET 2011


Krzysztof,

> 1. Is it less efficient if I expand a list before providing it as an
> argument for init?
>
> set myList [list 1 2 3 4]
>
> MyClass myObject $myList
>
> vs
>
> eval MyClass myObject $myList

well, it depends on what you want to achieve. Is it just about boxing 
the arguments in a list and then, for further processing unboxing it 
(e.g., in the init body?). Or are the values treated as a list in 
follow-up steps?

the script below sheds some light on various scenarios (you can run it 
to reproduce on your machine; timing in microsecs per iteration, 10000 
iterations each):

t.001:	  26.2 mms, MyClass myObject $myList; set ::out
t.002:	  32.6 mms, eval MyClass myObject $myList; set ::out
t.003:	  26.9 mms, MyClass myObject 1 2 3 4; set ::out
t.004:	  26.0 mms, MyClass myObject {*}$myList; set ::out

from this bird eye perspective (and without knowing the details of your 
scenario), you might want to consider avoiding the [eval] overhead by 
using the {*} operator in 8.5+ for the boxing case ...

(t.003 is a kind of baseline measurement and appears slightly more 
expensive because the values in the argument vector must be turned into 
Tcl_Objs first etc., a conversion which has already been achieved if 
dealing with a [list] and its values).

> 2. When do I need to create a custom destructor? I create objects inside
> init - do I have to do that in this case, or will those object be
> destroyed automatically when I destroy their parent?
>
> MyClass instproc init args {
>
> my contains {
> MySecondClass innerObject
> }
> }

The deletion of parents cascades. So there is no need for a custom 
destructor on a parent to deal with its kids.

//stefan




>
> Best Regards,
> Krzysztof
>
>
>
> _______________________________________________
> Xotcl mailing list
> Xotcl at alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl


-- 
Institute for Information Systems and New Media
Vienna University of Economics and Business
Augasse 2-6, A-1090 Vienna

`- http://nm.wu.ac.at/en/sobernig
`- stefan.sobernig at wu.ac.at
`- ss at thinkersfoot.net

`- +43-1-31336-4878 [phone]
`- +43-1-31336-746 [fax]


More information about the Xotcl mailing list