Krzysztof,
- 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).
- 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@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl