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

Re: Very basic questions



On Wed, 20 Jan 1999 19:12:38 CST, "Sanjay K. Agrawal" wrote: 
>Hi folks,
>
>I am a new user to NS2. I have been struggling for past month or so to
>modify
>NS2 to make event based changes.
>
>I have some very basic questions for which I didn't get satisfactory
>answer 
>from NS2 documentation (I have read it all). These questions are
>following:
>
>1: In tcl function always begins with code like following:
>  
>CBQLink instproc init { src dst bw delay q cl {lltype "DelayLink"} } {
>        $self next $src $dst $bw $delay $q $lltype ; # SimpleLink ctor
>        $self instvar head_ queue_ link_
>        $self instvar  classifier_      ; # not found in a SimpleLink
>#       $self instvar  drophead_ ; # not found in a SimpleLink
>
>        $queue_ link $link_ ; # queue_ set by SimpleLink ctor, CBQ needs
>$link_
>        set classifier_ $cl
>
>I don't understand what does the variable $self mean, what does next
>mean,
>I am not clear on instvar either. Does instavar make all the private
>variables
>accessible.

No, only the specifically listed variables.  See the OTcl documentation.

>2: When I bind a variable like following in the queue.cc:
>
>Queue::Queue() : Connector(), blocked_(0), unblock_on_resume_(1),
>qh_(*this), 
>	pq_(0)			/* temporarily NULL */
>{
>	bind("limit_", &qlim_);
>	bind_bool("blocked_", &blocked_);
>	bind_bool("unblock_on_resume_", &unblock_on_resume_);
>	bind_bool("control_jitter_", &control_jitter_);
>}
>
>It compiles fine but give me segmentation fault when I run tcl script.

This code shouldn't segfault, although you don't show your definition.

Also, you may find it easier to move your code forward to future ns
releases if you make your new queue type as a subclass of queue
rather than just directly modifying queue itself.

>I even have the following code in ns-defaults.tcl
>
>Queue set control_jitter_ false
>
>In addition I don't understand the fist line of this code in queue.cc.
>What are
>they trying to do.
>
>Queue::Queue() : Connector(), blocked_(0), unblock_on_resume_(1),
>qh_(*this), 
>	pq_(0)			/* temporarily NULL */
>

This is C++ syntax to initialize variables when making a new object
instance.  See Stroustroup or a C++ book for details.

It's good TclCL style to only initialize variables in OTcl (like
"Queue set control_jitter_ false") or C++ (like blocked_(0)), not both
places.  (Since only one will be effective anyway, the other is just
confusing.)

   -John Heidemann