[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] Why bind variables ?



> OTOH method 1 might be useful in cases where the variable is dynamic
> (value changes thruout the simulation) and needs to be updated both in OTcl and
> C++. a good example might be TCP parameters.

The overhead of using a bound variable is comparable to an otcl
linkage. When you change its value from otcl, both end up with a
translation from string value back to c++ (method 1 uses Tcl_TraceVar to
go to InstVar*, while method 2 directly go to OTclDispatch then to
command()). Reading from otcl goes through a similar path.

The only extra work of method 2 is to lookup the otcl object and to
evaluate the otcl instproc. This may be reduced if you invoke it via
'$o cmd abc' instead of '$o abc'; which eliminates going through the
unknown{} instproc of SplitObject.

So in general, I agree. But I guess this only happens when you have some
bound variable that is updated very frequently, e.g., in a tight loop,
from within OTCL. (in this sense I don't think the TCP parameters need to
be fully bound variables since most TCP code is in c++. I'd rather see
them gone to save the memory for bigger simulations...)

- Haobo

PS: a bound variable of a protocol agent allows you to trace its value
changes using otcl linkage 'trace' of TclObject, so that any updates to
the variable will be automatically written into a nam trace file.